请告知如何检查新的Woocommerce订单中某些商品是否存在“延期交货”元字段。我正在尝试为新订单上的客户添加注释,但无法找出为什么我的功能不起作用:
function tt_backorder_warning_note ( $order_id ) {
$tt_order = new WC_Order( $order_id );
$tt_items = $tt_order->get_items();
$tt_backorder = FALSE;
$tt_backordered_note = 'Some text to warn customer that they will wait longer';
foreach ($tt_items as $tt_item) {
if ($tt_item['Предзаказано']) { // Предзаказано = Backordered
$tt_backorder = TRUE;
break;
}
}
if($tt_backorder) {
$tt_order->add_order_note( $tt_backordered_note, $is_customer_note = 1 );
}
}
add_action( 'woocommerce_new_order', 'tt_backorder_warning_note' );
答案 0 :(得分:0)
您需要在产品上获取元数据:
function tt_backorder_warning_note ( $order_id ) {
$tt_order = new WC_Order( $order_id );
$tt_items = $tt_order->get_items();
$tt_backorder = FALSE;
$tt_backordered_note = 'Some text to warn customer that they will wait longer';
foreach ($tt_items as $tt_item) {
if ($tt_item->is_on_backorder()) {
$tt_backorder = TRUE;
break;
}
}
if($tt_backorder) {
$tt_order->add_order_note( $tt_backordered_note);
}
}
add_action( 'woocommerce_new_order', 'tt_backorder_warning_note' );