1

I would like to change the woocommerce order status auotmatically from "on-hold" to "processing" for every new order, except for payment method BACS (Direct Bank Transfer). I already found this code, but do not know how to adapt it to exclude payments made with BACS.

add_action( 'woocommerce_thankyou', 'woocommerce_auto_processing_orders');
function woocommerce_auto_processing_orders( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // If order is "on-hold" update status to "processing"
    if( $order->has_status( 'on-hold' ) ) {
        $order->update_status( 'processing' );
    }
}

Thank you for your help!

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
wpabud
  • 23
  • 3

1 Answers1

1

Update related to your comment based on WooCommerce: Auto complete paid orders answer thread.

Try the following:

add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
function wc_auto_complete_paid_order( $status, $order_id, $order ) {
    return 'processing';
}

It should work.


Original answer (based on the question code):

You can use WC_Order get_payment_method() method as follow:

add_action( 'woocommerce_thankyou', 'woocommerce_auto_processing_orders');
function woocommerce_auto_processing_orders( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // If order is "on-hold" update status to "processing" except for "BACS" payments
    if( $order->has_status( 'on-hold' ) && $order->get_payment_method() !== 'bacs' ) {
        $order->update_status( 'processing' );
    }
}

It should work.

Related: WooCommerce: Auto complete paid orders

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thanks a lot for your help, but unfortunately it is not working for one payment method i have integrated via stripe. It is a local payment method in germany called "Sofortüberweisung". The orders are still "on-hold" for this payment method and do not change to processing automatically. Any ideas how to solve? :( I have pasted the code in my functions.php (child theme) and have deleted the cache. – wpabud Sep 15 '20 at 17:41
  • I am using this stripe plugin: https://wordpress.org/plugins/woocommerce-gateway-stripe/ – wpabud Sep 15 '20 at 18:53
  • Thank you, really appreciate your support! I should also mention that after the customer ordered with payment method "Sofortüberweisung", it takes several days until stripe/woocommerce receives the payment. I tried the updated code with no success. I think after receipt of payment your updated code will change the status to processing, but not before. But in my case, it is necessary to have the status update immediately after the customer made his order (although money has not been received yet). – wpabud Sep 16 '20 at 15:30
  • The background is that a coupon will be generated automatically in status "processing" directly after ordering and will be send via mail to the customer. The customer should not wait for his coupon until I received the payment. Sorry if this information was relevant to know! – wpabud Sep 16 '20 at 15:31