WooCommerce 变更单状态 BACS 处理 [英] WooCommerce change order status BACS processing

查看:63
本文介绍了WooCommerce 变更单状态 BACS 处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WooCommerce 中,通过 BACS(直接银行转帐)下的任何订单都设置为 "on-hold".

In WooCommerce any order placed with the BACS (direct bank transfer) is set to "on-hold".

如何将其自动更改为处理?

How would one go about changing this automatically to processing?

我不想它在 functions.php

I wan't it to work inside the functions.php

我有以下代码但不起作用:

I have the following code but that doesn't work:

add_filter( 'woocommerce_payment_complete_order_status', 'rfvc_update_order_status', 10, 2 );

function rfvc_update_order_status( $order_status, $order_id ) {
    $order = new WC_Order( $order_id );
    if ( 'on-hold' == $order_status && 'on-hold' == $order->status ) {
        return 'processing';
    }
    return $order_status;
}

任何帮助都会很棒!

推荐答案

2020 新更新

WooCommerce 3.4 版引入了比 woocommerce_thankyouwoocommerce_thankyou_bacs 更好的钩子,它允许更改 BACS 付款方式的默认订单状态.

WooCommerce version 3.4 has introduced a much better hook than woocommerce_thankyou or woocommerce_thankyou_bacs, that allows to change the default order status for BACS payment method.

使用这个钩子将:

  • 清楚地减轻必要的代码,
  • 避免等待"下 BACS 订单时通知客户.

因此请改用以下内容:

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

代码位于活动子主题(或活动主题)的functions.php 文件中.经测试有效.

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

原答案:

更新 (最后添加了woocommerce 3+的版本)

似乎 woocommerce_payment_complete_order_status 动作钩子不会用 BACS 付款方式触发.

It seems that woocommerce_payment_complete_order_status action hook doesn't trigger with BACS payment method.

基于这个主题, 'woocommerce_thankyou' 动作钩子做这个工作:

Based on this thread, 'woocommerce_thankyou' action hook does the job:

add_action( 'woocommerce_thankyou', 'bacs_order_payment_processing_order_status', 10, 1 );
 
function bacs_order_payment_processing_order_status( $order_id ) {
    if ( ! $order_id ) {
        return;
    }

    // Get an instance of the WC_Order object
    $order = new WC_Order( $order_id );
 
    if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' ) && ('on-hold' == $order->status || 'pending' == $order->status) ) {
        $order->update_status('processing');
    } else {
        return;
    }
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of your active child theme (or active theme). tested and works.

对于 woocommerce 3+ 版本:

这里我们使用了类似的复合钩子woocommerce_thankyou_{$order->get_payment_method()}:

Here we use the similar composite hook woocommerce_thankyou_{$order->get_payment_method()}:

add_action( 'woocommerce_thankyou_bacs', 'bacs_order_payment_processing_order_status', 10, 1 );
function bacs_order_payment_processing_order_status( $order_id ) {
    if ( ! $order_id ) {
        return;
    }

    // Get an instance of the WC_Order object
    $order = wc_get_order( $order_id );
 
    if ( in_array( $order->get_status(), array('on-hold', 'pending') ) ) {
        $order->update_status('processing');
    } else {
        return;
    }
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.

Code goes in function.php file of your active child theme (or active theme). tested and works.

这篇关于WooCommerce 变更单状态 BACS 处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆