배송 방법으로 "빠른 배송"을 주문하면 주문 상태가 On-Hold로 업데이트됩니다.배송 방법에 따라 Woocommerce 주문 상태 변경
내가 다른 약간의 "속달 배달"배송 방법 요금을 가지고 있다고 생각했는데 '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;
}
}
편집 :
여기는 내가 가지고있는 코드입니다 -----------------------------
Woocommerce 테이블 전송을 사용하는 사용자는 get_method_id가 테이블 속도 ID를 반환하므로 의견을하시기 바랍니다 더 좋은 방법이 있다면 나는 빠르고 적은 메모리 집약적 인 재미를 사용하는 것을 선호 ... 아래로 대신
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의 가치가 무엇인지 디버깅하는. –