Display value from ACF field in Woocommerce order email

↘锁芯ラ 提交于 2020-01-05 09:14:56

问题


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.

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

回答1:


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

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

For reference see: Get Order items and WC_Order_Item_Product in Woocommerce 3



来源:https://stackoverflow.com/questions/52942884/display-value-from-acf-field-in-woocommerce-order-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!