【发布时间】:2019-08-08 21:26:27
【问题描述】:
在 Woocommerce 中,当客户帐单/送货地址是特定城市时,我正在尝试修改客户订单备注以显示“与此提供商一起发货”。
WordPress 5.2.2 WooCommerce 3.6.5
我正在使用woocommerce_thankyou钩子,通过订单ID和get_customer_note()、set_customer_note()获取订单数据。
add_action('woocommerce_thankyou','route_mail_on_customer_location', 30, 1);
function route_mail_on_customer_location($order_id){
$CP_cities = ["City 1", "City 2", "City 3"];
$order = wc_get_order( $order_id );
$curr_note = $order->get_customer_note();
echo "<p>Customer note: " . $curr_note . "</p>";
if((strpos($curr_note, "Ship with Canada Post.") == false) && (in_array($order->get_shipping_city(), $CP_cities, true))){
$note = __($curr_note . ". Ship with Canada Post.");
$order->set_customer_note($note);
}
echo "<p>Customer note: " . $order->get_customer_note() . "</p>";
}
回显结果正确显示。
Customer note: Test Note
Customer note: Test Note Ship with Canada Post.
当我查看订单页面时,订单备注只是原始客户备注。
Customer provided note:
Test Note
看起来 setter 没有将更改发送到数据库。我需要调用一种方法来确保将我的更改添加到数据库中,还是应该直接通过 wpdb 查询来完成?
编辑:更正回显结果以反映代码。
【问题讨论】:
标签: php mysql wordpress woocommerce