gpt4 book ai didi

php - 创建订单时将 WooCommerce 订单状态从处理中设置为待处理

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:02:18 25 4
gpt4 key购买 nike

创建 woocommerce 订单时,订单状态为“处理中”。我需要将默认订单状态更改为“待处理”。

我怎样才能做到这一点?

最佳答案

默认订单状态由支付方式或支付网关设置。

您可以尝试使用此自定义 Hook 函数,但它不会工作 (因为此 Hook 在支付方式和支付网关之前触发):

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' );
}

显然每种支付方式(和支付网关)都在设置订单状态(取决于支付网关的交易响应)......

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

现在您可以更新订单状态使用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 文件中或任何插件文件中。

已测试并有效

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 the IF statement will not match anymore and nothing else will happen.


相关主题:WooCommerce: Auto complete paid Orders (depending on Payment methods)

关于php - 创建订单时将 WooCommerce 订单状态从处理中设置为待处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45985488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com