Tristan .L Tristan .L - 5 months ago 127
PHP Question

WooCommerce change order status BACS processing

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!

Answer

(update)

It seems that the add_filter( 'woocommerce_payment_complete_order_status', 'my_custom_function', 10, 2 ); doesn't trigger with BACS payment method.

Based on this thread, add_action( 'woocommerce_thankyou', 'my_custom_function', 10, 1 ); 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;

  }

  global $woocommerce;
  $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;

  }

}