問(wèn)題描述
創(chuàng)建 woocommerce 訂單后,訂單狀態(tài)為正在處理".我需要將默認(rèn)訂單狀態(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".
我怎樣才能做到這一點(diǎn)?
How can I achieve this?
推薦答案
默認(rèn)訂單狀態(tài)由支付方式或支付網(wǎng)關(guān)設(shè)置.
The default order status is set by the payment method or the payment gateway.
您可以嘗試使用此自定義掛鉤函數(shù),但它不起作用 (因?yàn)榇藪煦^在付款方式和支付網(wǎng)關(guān)之前被觸發(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' );
}
顯然,每種支付方式(和支付網(wǎng)關(guān))都在設(shè)置訂單狀態(tài)(取決于支付網(wǎng)關(guān)的交易響應(yīng))......
Apparently each payment method (and payment gateways) are setting the order status (depending on the transaction response for payment gateways)…
對(duì)于貨到付款付款方式,可以使用專(zhuān)用過(guò)濾器鉤子進(jìn)行調(diào)整,請(qǐng)參閱:
貨到付款默認(rèn)訂單狀態(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
現(xiàn)在您可以更新訂單狀態(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' );
}
代碼位于活動(dòng)子主題(或主題)的 function.php 文件或任何插件文件中.
經(jīng)過(guò)測(cè)試并有效
注意:鉤子 woocommerce_thankyou
會(huì)在每次收到訂單頁(yè)面加載時(shí)觸發(fā),因此需要小心使用...
現(xiàn)在上面的函數(shù)只會(huì)在第一次更新訂單狀態(tài).如果客戶重新加載頁(yè)面,IF
語(yǔ)句中的條件將不再匹配,其他任何事情都不會(huì)發(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.
<小時(shí)>
相關(guān)主題:WooCommerce:自動(dòng)完成支付訂單(取決于付款方式)
這篇關(guān)于創(chuàng)建訂單從處理到待處理時(shí)設(shè)置 WooCommerce 訂單狀態(tài)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!