問題描述
創(chuàng)建 woocommerce 訂單后,訂單狀態(tài)為正在處理".我需要將默認訂單狀態(tài)更改為待處理".
When a woocommerce order is created the status of the order is "processing". I need to change the default order-status to "pending".
我怎樣才能做到這一點?
How can I achieve this?
推薦答案
默認訂單狀態(tài)由支付方式或支付網關設置.
The default order status is set by the payment method or the payment gateway.
您可以嘗試使用此自定義掛鉤函數,但它不起作用 (因為此掛鉤在付款方式和支付網關之前被觸發(fā)):
You could try to use this custom hooked function, but it will not work (as this hook is fired before payment methods and payment gateways):
add_action( 'woocommerce_checkout_order_processed', 'changing_order_status_before_payment', 10, 3 );
function changing_order_status_before_payment( $order_id, $posted_data, $order ){
$order->update_status( 'pending' );
}
顯然,每種支付方式(和支付網關)都在設置訂單狀態(tài)(取決于支付網關的交易響應)......
Apparently each payment method (and payment gateways) are setting the order status (depending on the transaction response for payment gateways)…
對于貨到付款付款方式,可以使用專用過濾器鉤子進行調整,請參閱:
貨到付款默認訂單狀態(tài)為暫停"而不是處理"在 Woocommerce
For Cash on delivery payment method, this can be tweaked using a dedicated filter hook, see:
Change Cash on delivery default order status to "On Hold" instead of "Processing" in Woocommerce
現在您可以更新訂單狀態(tài)使用woocommerce_thankyou
鉤子:
Now instead you can update the order status using woocommerce_thankyou
hook:
add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
if( $order->get_status() == 'processing' )
$order->update_status( 'pending' );
}
代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.
經過測試并有效
注意:鉤子 woocommerce_thankyou
會在每次收到訂單頁面加載時觸發(fā),因此需要小心使用...
現在上面的函數只會在第一次更新訂單狀態(tài).如果客戶重新加載頁面,IF
語句中的條件將不再匹配,其他任何事情都不會發(fā)生.
Note: The hook
woocommerce_thankyou
is fired each time the order received page is loaded and need to be used with care for that reason...
Now the function above will update the order status only the first time. If customer reload the page, the condition in theIF
statement will not match anymore and nothing else will happen.
<小時>
相關主題:WooCommerce:自動完成支付訂單(取決于付款方式)
這篇關于創(chuàng)建訂單從處理到待處理時設置 WooCommerce 訂單狀態(tài)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!