将默认的 WooCommerce 订单状态更改为处理支票和 bacs 付款 [英] Change default WooCommerce order status to processing for cheque and bacs payments
问题描述
在 WooCommerce 中,我需要我的所有订单立即进入正在处理"状态,以便在处理订单时直接发送订单处理电子邮件.
In WooCommerce, I need all my orders to go immediately to "processing" status to have the order-processing email sent directly when the order is processed.
默认情况下,此行为适用于 Paypal 和 COD 订单,但不适用于 BACS 和支票,其中默认状态为 on-hold
.
By default, this behavior exist for Paypal and COD orders, but not for BACS and Cheque where the default status is on-hold
.
我尝试了几个这样的片段:
I tried several snippets like this one:
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_process_order' );
function custom_woocommerce_auto_process_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'processing' );
}
但这不起作用,订单仍显示为暂停"状态,并且未发送处理电子邮件通知.现在我刚刚找到了这个片段:
But this doesn't work, the order still shows up in "on-hold" status and the processing email notification is not sent. Now I just found a this snippet:
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
它有效,但仅适用于BACS".我如何才能使其适用于支票"订单?
And it works, but only for "BACS". How can I adapt it to also work for "Cheque" orders?
推荐答案
过滤器钩子
woocommerce_cheque_process_payment_order_status
尚未在 Woocommerce 3.5.7 中实现……如果您查看位于 woocommerce 插件中的文件:
includes
>网关
>支票
>class-wc-gateway-cheque.php
,缺少钩子(行122
):
The filter hook
woocommerce_cheque_process_payment_order_status
is not yet implemented in Woocommerce 3.5.7 … if you look to the file located in your woocommerce plugin under:
includes
>gateways
>cheque
>class-wc-gateway-cheque.php
, the hook is missing (line122
):
$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
但在 Github WC 版本 3.5.7 上 class-wc-gateway-cheque.php
文件,钩子存在(行122
):
But on Github WC version 3.5.7 for class-wc-gateway-cheque.php
file, the hook exist (line 122
):
$order->update_status( apply_filters( 'woocommerce_cheque_process_payment_order_status', 'on-hold', $order ), _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
该钩子计划在下一个 WooCommerce 3.6 版本中可用,查看 Woocommerce 上的文件更改GitHub.它被标记为 3.6.0-rc.2
和 3.6.0-beta.1
The hook will is planed to be available next WooCommerce 3.6 release, see the file change on Woocommerce Github. It's tagged 3.6.0-rc.2
and 3.6.0-beta.1
因此可以将默认订单状态更改为正在处理"为bacs"和支票"付款方式,使用以下:
So it will be possible to change the default order status to "processing" for "bacs" and "cheque" payment methods, using the following:
add_filter( 'woocommerce_bacs_process_payment_order_status','filter_process_payment_order_status_callback', 10, 2 );
add_filter( 'woocommerce_cheque_process_payment_order_status','filter_process_payment_order_status_callback', 10, 2 );
function filter_process_payment_order_status_callback( $status, $order ) {
return 'processing';
}
代码位于活动子主题(或活动主题)的 function.php 文件中.
Code goes in function.php file of your active child theme (or active theme).
这篇关于将默认的 WooCommerce 订单状态更改为处理支票和 bacs 付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!