[英]WooCommerce order status change from payment gateway
I have integrated a payment gateway to accept online payments for my store running on woocommerce.我已经集成了一个支付网关来接受我在 woocommerce 上运行的商店的在线支付。 Everything works fine but I noticed that woocommerce is changing the order status to
wc-processing
for all the online paid orders by default.一切正常,但我注意到 woocommerce 默认将所有在线支付订单的订单状态更改为
wc-processing
。
As per my store's functionality I want all the online paid orders to be in wc-on-hold
status initially.根据我商店的功能,我希望所有在线支付订单最初都处于
wc-on-hold
状态。
Is there any way to stop woocommerce changing the order status to wc-processing
programatically?有没有办法阻止 woocommerce 以编程方式将订单状态更改为
wc-processing
?
yes there is a way, but you need to modify the payment plugin or add your own code, you can read this to understand how payments work. 是的,有一种方法,但是您需要修改付款插件或添加自己的代码,可以阅读此书以了解付款方式。
Now, woocommerce use $order->payment_complete()
method to handle the completed order, so you need to hook your own function to modify the status, 现在,woocommerce使用
$order->payment_complete()
方法来处理已完成的订单,因此您需要连接自己的函数来修改状态, here is the description of that method 这是该方法的描述
Use this filter: woocommerce_payment_complete_order_status
使用此过滤器:
woocommerce_payment_complete_order_status
Here it is a code snippet based on this thread . 这是基于此线程的代码片段。 We use here
woocommerce_thankyou
(that is fired just after payment has been done) to hook our function, converting 'processing'
orders status to 'on-hold'
: 我们在这里使用
woocommerce_thankyou
(只支付已经完成之后被解雇)挂钩我们的功能,将'processing'
订单状态'on-hold'
add_action( 'woocommerce_thankyou', 'custom_woocommerce_paid_order_status', 10, 1 );
function custom_woocommerce_paid_order_status( $order_id ) {
if ( ! $order_id ) {
return;
}
global $woocommerce;
$order = new WC_Order( $order_id );
// 'processing' orders status are converted to 'on-hold'.
if ( is_object($order) && $order->has_status( 'processing' ) {
$order->update_status( 'on-hold' );
}
return;
}
You can also target in your conditions the payment gateways for example here we bypass 3 payment gateways and target a specific payment gateway using "your_payment_gateway"
slug : 您还可以根据自己的条件定位支付网关,例如,此处我们绕过3个支付网关,并使用
"your_payment_gateway"
定位特定的支付网关:
add_action( 'woocommerce_thankyou', 'custom_woocommerce_paid_order_status', 10, 1 );
function custom_woocommerce_paid_order_status( $order_id ) {
if ( ! $order_id ) {
return;
}
global $woocommerce;
$order = new WC_Order( $order_id );
// Bypass orders with Bank wire, Cash on delivery and Cheque payment methods.
if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' ) || ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) || ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) ) {
return;
}
// Target your "your_payment_gateway_slug" with this conditional
if ( is_object($order) && get_post_meta($order->id, '_payment_method', true) == 'your_payment_gateway_slug' && $order->has_status( 'processing' ) ) {
$order->update_status( 'on-hold' );
}
return;
}
This code snippets goes on function.php file of your active child theme or theme. 此代码段位于您的活动子主题或主题的function.php文件中。
You can easily do anything you want, and the correct hook for paid orders is woocommerce_thankyou
您可以轻松地做任何您想做的事,正确的付款订单挂钩是
woocommerce_thankyou
References: 参考文献:
I found this plugin that worked for me!我发现这个插件对我有用!
https:\/\/wpfactory.com\/item\/order-status-rules-for-woocommerce\/<\/a>
https:\/\/wpfactory.com\/item\/order-status-rules-for-woocommerce\/<\/a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.