ここでの考え方は、出荷方法として「速達」が指定された注文がオン・ホールドに更新されるという考え方です。そこに私は言葉'express'
はどこにでもフォーマットされた配送方法タイトルに表示されるかどうかを確認するためにstristr()
を使用していると考え、いくつかの異なる「速達」配送方法・レートを持つ配送方法に基づいて、ウーココマスの注文ステータスを変更します。
。しかし、私は何も手に入らないので何かが欠けているようです。
注文状況を更新できるように、注文発送方法が「速達」であるかどうかを確認するにはどうすればよいですか?
add_action('woocommerce_thankyou', 'express_orders_4865', 10, 1);
function express_orders_4865($order_id) {
global $woocommerce;
$order = new WC_Order($order_id);
$shipping_method = $order->get_shipping_method();
if (stristr($shipping_method, 'express') === TRUE) {
$order->update_status('on-hold');
} else {
return;
}
}
EDIT ------------------------------:ここ
は、私が持っているコードです。 -----------------------------
Woocommerce Table Rate Shippingを使用している場合、get_method_idはテーブルレートIDを返します。代わりに、以下のようにget_method_titleを使用してください。
add_action('woocommerce_thankyou', 'express_shipping_update_order_status', 10, 1);
function express_shipping_update_order_status($order_id) {
if (! $order_id) return;
$search = 'Express'; // The needle to search in the shipping method ID
// Get an instance of the WC_Order object
$order = wc_get_order($order_id);
// Get the WC_Order_Item_Shipping object data
foreach($order->get_shipping_methods() as $shipping_item){
// When "express delivery" method is used, we change the order to "on-hold" status
if(strpos($shipping_item->get_method_title(), $search) !== false){
$order->update_status('on-hold');
break;
}
}
}
$ SHIPPING_METHODの値が何であるかをデバッグする書き込み。 –