Woocommerce禁用自动订单状态更改挂起->处理 [英] Woocommerce disable automatic order status change pending->processing
问题描述
我要禁用此选项:
每当有人在我的网站上进行订购并付款成功后,订单状态就会自动从待处理变为.
I want to dissable this option:
Whenever someone makes and order on my site and the payment is successfull the order status automaticaly changes from pending to processing.
但是我不想要此功能已启用.相反,我想在进行订单时手动进行操作.
However I don`t want this feature to have enabled. Rather I want to do it manually when i proces the orders.
我在woocommerce中发现了此功能,这使得该功能成为可能.我不想直接在此处更改它,而希望使用某种覆盖该功能的php代码段.
I found this function in the woocommerce which is making this feature possible. I don`t want to directly change it there but rather with some kind of php snippet which overrides this function.
这是我需要更改的功能: http://woocommerce.wp- a2z.org/oik_api/wc_orderpayment_complete/
Here is the function which i need to change : http://woocommerce.wp-a2z.org/oik_api/wc_orderpayment_complete/
PS:我很难正确地做到这一点.
PS: I just having a hard time to do it correctly.
推荐答案
更新
此payment_complete()
可能与您要查找的过程无关.另外,您可以尝试使用woocommerce_thankyou
操作挂钩:
May be this payment_complete()
is not involved in the process you are looking for. Alternatively, what you could try is the woocommerce_thankyou
action hook instead:
add_action( 'woocommerce_thankyou', 'thankyou_order_status', 10, 1 );
function thankyou_order_status( $order_id ){
if( ! $order_id ) return;
$order = new WC_Order( $order_id ); // Get an instance of the WC_Order object
if ( $order->has_status( 'processing' ) )
$order-> update_status( 'pending' )
}
您可以使用相同的替代钩子:woocommerce_thankyou_{$order->get_payment_method()}
(用付款方式ID slug替换$order->get_payment_method()
)
You can use the same alternative hook: woocommerce_thankyou_{$order->get_payment_method()}
(replacing $order->get_payment_method()
by the payment method ID slug)
代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
此代码已在Woocommerce 3+上进行了测试,并且可以正常工作.
This code is tested on Woocommerce 3+ and works.
使用挂钩在 woocommerce_valid_order_statuses_for_payment_complete
过滤器挂钩中的自定义功能,您将在其中返回所需的订单状态,这些状态可由相关功能payment_complete()
获取,该功能负责自动更改订单状态
Using a custom function hooked in woocommerce_valid_order_statuses_for_payment_complete
filter hook, where you will return the desired orders statuses that can be taken by the related function payment_complete()
which is responsible of auto change the order status.
默认情况下,过滤器中的订单状态数组为:
By default the array of order statuses in the filter is:
array( 'on-hold', 'pending', 'failed', 'cancelled' ).
我们可以通过以下方式删除保留"订单状态:
And we can remove 'on-hold' order status this way:
add_filter( 'woocommerce_payment_complete_order_status', 'disable_auto_order_status', 10, 2 );
function disable_auto_order_status( $order_statuses, $order ) {
$return array( 'pending', 'failed', 'cancelled' );
}
代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
此代码已在Woocommerce 3+上进行了测试,并且可以正常工作.
This code is tested on Woocommerce 3+ and works.
这篇关于Woocommerce禁用自动订单状态更改挂起->处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!