5
votes

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?

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;
}

Any help would be great!

3
I decided to go for the second approach as it seems the first filter does not trigger with the BACS payment.Tristan .L

3 Answers

11
votes

New 2020 update

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.

Using this hook will:

  • clearly lighten the necessary code,
  • avoid "on-hold" notification to the customer when a BACS order is placed.

So use instead the following:

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';
}

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


Original answer:

Update (added a version for woocommerce 3+ at the end)

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

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;
    }
}

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


For woocommerce 3+ versions:

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;
    }
}

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

5
votes

There is a new filter which will allow you to set the status when BACS 'payment' is processed.

/**
 * Change the default status when BACS 'payment' is processed.
 * 
 * @see WC_Gateway_BACS::process_payment()
 * woocommerce/includes/gateways/bacs/class-wc-gateway-bacs.php:362
 * @since Mar 8, 2018
 * @link https://github.com/woocommerce/woocommerce/blob/750fda3b1b55c55645f626d3873d956282e3ac1b/includes/gateways/bacs/class-wc-gateway-bacs.php#L364
 * 
 * @filter woocommerce_bacs_process_payment_order_status
 * @priority 10
 * @args 2
 * 
 * @param string $status Status to filter. Default 'on-hold'.
 * @param WC_Order $order
 * @return string New status 'processing'.
 */
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
    return 'processing';
}, 10, 2 );
1
votes

Try changing the code to this:

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

The key change here is this:

$order->update_status('processing', 'order_note');

You can add order note too if you prefer.