将默认 WooCommerce 订单状态更改为处理支票和 bacs 付款

Change default WooCommerce order status to processing for cheque and bacs payments

在 WooCommerce 中,我需要将所有订单立即转到 "processing" 状态 ,以便在处理订单时直接发送订单处理电子邮件。

默认情况下,Paypal 和 COD 订单存在此行为,但 BACS 和 Cheque 不存在,默认状态为 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' );
}

但这不起作用,订单仍然显示在 "on-hold" 状态并且未发送处理电子邮件通知。现在我刚刚找到了这个片段:

add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
    return 'processing';
}, 10, 2 );

它有效,但仅适用于 "BACS"。我怎样才能让它也适用于 "Cheque" 个订单?

你快到了。现在您正在为 BACS 挂钩添加过滤器。 Cheque 付款方式也有类似的钩子。

只需添加以下代码:

add_filter( 
  'woocommerce_cheque_process_payment_order_status',
  function( $status = 'on_hold', $order = null ) {
    return 'processing';
  }, 10, 2
);

它的作用完全相同,但只是针对 Cheque 个订单。

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 (line 122):

$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );

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 版本中可用,see the file change on Woocommerce Github。它被标记为 3.6.0-rc.23.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 文件。

我不能 100% 确定这是否与我遇到的问题相同 - 我必须将银行转帐的订单状态更改为与通过 PayPal 付款相同。我是在 this plugin.

的帮助下完成的

您可以创建自定义状态并为特定网关定义默认状态。我只需点击几下就解决了我的问题。