在Woocommerce订单电子邮件中的ACF字段中显示值 [英] Display value from ACF field in Woocommerce order email

查看:88
本文介绍了在Woocommerce订单电子邮件中的ACF字段中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I´m trying to display a value for delivery date in the emails that Woocommerce automatic sends to the customer when the order is being processed.

我创建了一个高级自定义字段值称为 leveranstid,我希望它与电子邮件中的所有产品一起显示。我试图将下面的代码添加到functions.php中,但似乎无法正常工作。什么都没显示。如果有人请帮助我,我将不胜感激?

I have created a Advanced custom field value called 'leveranstid' and I want it to be shown with every product in the email. I´ve tried to add the code below to the functions.php but it doesn´t seem to work. Nothing shows. I would be very grateful if someone please help me find what´s wrong?

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;
}


推荐答案

变量<$ c $没有在 $ leverans = get_field('leveranstid',$ post_id); 中定义c> $ post_id 。而是尝试:

The variable $post_id is not defined in $leverans = get_field('leveranstid', $post_id);. Instead try:

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字段。

It should work if 'leveranstid' ACF field is defined for your products.

有关参考,请参见:在Woocommerce 3中获取订单商品和WC_Order_Item_Product

这篇关于在Woocommerce订单电子邮件中的ACF字段中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆