在Woocommerce交易邮件中显示产品ACF字段值

3

是否可以在Woocommerce交易明细中的每个项目旁边添加使用ACF创建的自定义字段?

我有一个名为“shpng”的字段,其中包含运输日期,它每天从同步导入文件更改,并最终出现在每个产品的shpng字段下的数据库中。

1个回答

3
尝试以下步骤,可以在电子邮件通知中的项目名称下显示您的ACF值:
// Display Items Shipping ACF custom field value in email notification
add_filter( 'woocommerce_order_item_name', 'custom_order_item_name', 10, 2 );
function custom_order_item_name( $item_name, $item ) {
    // Targeting email notifications only
    if( is_wc_endpoint_url() ) 
        return $item_name;

    // Get the WC_Product object (from order item)
    $product = $item->get_product();

    if( $shpng_value = get_field('shpng', $product->get_id()) ) {
        $item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
        <strong>' . __( 'Shipping Date', 'woocommerce' ) . ': </strong>' . $shpng_value . '</p>';
    }
    return $item_name;
}

代码放在您活动的子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。

续集:在Woocommerce中显示每个项目名称旁边的购物车中的产品自定义字段


如果我想显示SKU值(并将其用于IF条件),该如何将其放入变量中?这个是正确的吗:$item_sku = $product->get_sku(),它能够完美运行。 - Wed

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接