【问题标题】:Display product ACF field value in Woocommerce transaction emails在 Woocommerce 交易电子邮件中显示产品 ACF 字段值
【发布时间】:2019-02-17 23:12:33
【问题描述】:

Woocommerce 交易详情中的每个项目旁边是否可以有一个自定义字段(使用 ACF 创建)?

我有一个名为“shpng”的字段,其中包含发货日期,并且每天都会从 syncsd 导入文件中更改,并最终在每个产品的 shpng 字段下的数据库中。

【问题讨论】:

    标签: php wordpress woocommerce advanced-custom-fields email-notifications


    【解决方案1】:

    尝试以下操作,以在电子邮件通知中的项目名称下显示您的 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 文件中。经过测试并且可以工作。

    继续: Display product custom fields in cart next to each item name in Woocommerce

    【讨论】:

    • 这就像一个魅力。如果我想显示 SKU 值(并将其用于 IF 条件),如何将其放入变量中?这是正确的:$item_sku = $product->get_sku()
    猜你喜欢
    • 2020-09-01
    • 1970-01-01
    • 2019-03-27
    • 2021-06-23
    • 2020-12-07
    • 2021-11-26
    • 2018-08-30
    • 2021-04-12
    相关资源
    最近更新 更多