[英]Change default WooCommerce order status to processing for cheque and bacs payments
在 WooCommerce 中,我需要我所有的订单立即进入“处理中”状态,以便在处理订单时直接发送订单处理电子邮件。
默认情况下,此行为存在于 Paypal 和 COD 订单,但不存在于默认状态为on-hold
的 BACS 和 Check 。
我尝试了几个这样的片段:
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' );
}
但这不起作用,订单仍显示为“暂停”状态,并且未发送处理电子邮件通知。 现在我刚刚找到了这个片段:
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
它有效,但仅适用于“BACS”。 我怎样才能使它也适用于“支票”订单?
过滤器挂钩
woocommerce_cheque_process_payment_order_status
尚未在 Woocommerce 3.5.7 中实现……如果您查看位于 woocommerce 插件中的文件,请执行以下操作:
includes
>gateways
>cheque
>class-wc-gateway-cheque.php
,缺少钩子(第122
行) :$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
但是在
class-wc-gateway-cheque.php
文件的 Github WC 版本 3.5.7 上,挂钩存在(第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
因此,可以使用以下方法将“bacs”和“支票”付款方式的默认订单状态更改为“处理中”:
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';
}
代码进入您的活动子主题(或活动主题)的 functions.php 文件。
您快到了。 现在您正在为BACS
挂钩添加过滤器。 Cheque
付款方式也有类似的钩子。
只需添加以下代码:
add_filter(
'woocommerce_cheque_process_payment_order_status',
function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2
);
它的作用完全相同,但仅适用于Cheque
订单。
在 WooCommerce 中,我需要我的所有订单立即进入“处理”状态,以便在处理订单时直接发送订单处理电子邮件。
默认情况下,此行为适用于 Paypal 和 COD 订单,但不适用于 BACS 和 Check where default status is on-hold
。
我尝试了几个这样的片段:
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' );
}
但这不起作用,订单仍显示为“暂停”状态,并且未发送处理电子邮件通知。 现在我刚刚找到了这个片段:
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
它有效,但仅适用于“BACS”。 我怎样才能使它适用于“支票”订单?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.