Woocommerce在下订单后更新order_comments

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

下订单时,需要将自定义字段附加到订单备注。我可以使用更新公司并将数字附加到最后

update_post_meta( $order_id, '_billing_company', $_companyName );

在管理员的订单详细信息页面上,调用运输详细信息下的字段

“客户提供的注释”在结帐页面上称为“order_comments”。

在订单详情页面上,它被称为“摘录”以及“post_excerpt”。如果我使用update_post_meta( $order_id, 'post_excerpt', $_urn ); ,该字段不会更新。我也试过excerpt和order_comments,我无法更新这个字段。

有任何想法吗?

php wordpress woocommerce orders
1个回答
1
投票

“客户提供的注释”存储为支持post_excerptorder post_type上的WC_Order。要更新它,您可以使用标准的WordPress Codex或wc_update_order()函数(它实际上是WordPress Codex的前端,但可能是正确的方法)。

// specify the order_id so WooCommerce knows which to update
$order_data = array(
    'order_id' => $order_id,
    'customer_note' => 'The customer note.'
);
// update the customer_note on the order
wc_update_order( $order_data );
© www.soinside.com 2019 - 2024. All rights reserved.