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

时间:2019-04-12 16:33:00

标签: php wordpress woocommerce orders payment-method

在WooCommerce中,我需要我所有的订单立即进入“处理中”状态,以便在处理订单时直接发送订单处理电子邮件。

默认情况下,贝宝和COD订单存在此行为,但默认状态为on-hold的BACS和支票不存在

我尝试了几个类似这样的片段:

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”。我怎样才能使其适应“支票”订单?

3 个答案:

答案 0 :(得分:1)

  

Woocommerce 3.5.7中尚未实现过滤器挂钩woocommerce_cheque_process_payment_order_status……如果您查看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 file的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版本see the file change on Woocommerce Github中提供。它被标记为3.6.0-rc.23.6.0-beta.1

因此,可以使用以下方式将“ bacs”和“ cheque”付款方式的默认订单状态更改为“处理中”:

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文件中。

答案 1 :(得分:0)

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

只需添加以下代码:

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

它的功能完全相同,但仅适用于Cheque个订单。

答案 2 :(得分:0)

我不是100%知道这是否与我遇到的问题相同-我必须将银行转帐的订单状态更改为与通过PayPal付款相同。我是在this plugin的帮助下完成的。

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