【问题标题】:Display value from ACF field in Woocommerce order email在 Woocommerce 订单电子邮件中显示 ACF 字段的值
【发布时间】:2019-03-27 07:51:56
【问题描述】:

我正在尝试在处理订单时 Woocommerce 自动发送给客户的电子邮件中显示交货日期的值。

我创建了一个名为“leveranstid”的高级自定义字段值,我希望它与电子邮件中的每个产品一起显示。我试图将下面的代码添加到functions.php,但它似乎不起作用。什么都没有显示。如果有人请帮我找出问题所在,我将不胜感激?

add_action( 'woocommerce_order_item_meta_start', 
'ts_order_item_meta_start', 10, 4 );
function ts_order_item_meta_start( $item_id, $item, $order, $plain_text 
) {

$leverans = get_field(’leveranstid’, $post_id);
echo $leverans;
}

【问题讨论】:

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


    【解决方案1】:

    变量$post_id 未在$leverans = get_field('leveranstid', $post_id); 中定义。而是尝试:

    add_action( 'woocommerce_order_item_meta_start', 'display', 10, 4 );
    function ts_order_item_meta_start( $item_id, $item, $order, $plain_text ) {
    
        if( $leverans = get_field( 'leveranstid', $item->get_product_id() ) ;
            echo $leverans;
    }
    

    如果为您的产品定义了'leveranstid' ACF 字段,它应该可以工作。

    参考见:Get Order items and WC_Order_Item_Product in Woocommerce 3

    【讨论】:

    • 谢谢,但我仍然看不到订单电子邮件中的价值。而且,是的,“leveranstid”这个词是在我的产品中定义的。
    猜你喜欢
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2021-03-29
    • 2020-09-09
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多