在WooCommerce客户备注中添加多个自定义字段。

问题描述 投票:1回答:1

我需要从一个交付插件中检索3个自定义字段,并将它们的值放在同一个woocommerce私注中。我正在使用这段代码,它的工作原理为第一个自定义字段。delivery_date 但其他的就不一样了(我试了 false 在最后)。)

add_action( 'woocommerce_new_order', 'add_engraving_notes' );
function add_engraving_notes( $order_id ) {

//because I already have the ID from the hook I am using.
$order = wc_get_order( $order_id );

// The text for the note
$note = get_post_meta( $order_id, 'delivery_date', 'time_slot_from', 'time_slot_to', true );

// Add the note
$order->add_order_note( $note );

// Save the data
$order->save();
}

谢谢你的帮助

php wordpress woocommerce hook-woocommerce orders
1个回答
0
投票
add_action( 'woocommerce_new_order', 'add_engraving_notes' );

function add_engraving_notes( $order_id ) {

//because I already have the ID from the hook I am using.
    $order = wc_get_order( $order_id );

// The text for the note
    $delivery_date   = get_post_meta( $order_id, 'delivery_date', true );
    $time_slot_from  = get_post_meta( $order_id, 'time_slot_from', true );
    $time_slot_to    = get_post_meta( $order_id, 'time_slot_to', true );

    $note = "Deliver Date:$delivery_date Time Slot From: $time_slot_from Time Slot To: $time_slot_to";

// Add the note
    $order->add_order_note( $note );

// Save the data
    $order->save();
}

试试这个

© www.soinside.com 2019 - 2024. All rights reserved.