Home > Software design >  Immediately set on-hold orders to processing in WooCommerce and send the processing email notificati
Immediately set on-hold orders to processing in WooCommerce and send the processing email notificati

Time:10-28

I need to set all WooCommerce orders that come in as "on-hold" to "processing" and also have the order-processing email sent out immediately.

I tried this

function custom_woocommerce_auto_order( $order_id ) {
if ( ! $order_id ) {
    return;
}

$order = wc_get_order( $order_id );
if( 'on-hold'== $order->get_status() ) {
    $order->update_status( 'processing' );
}
}
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_order' );

Although the status changes, the "on-hold" email notification will still be sent even though it should only be the "processing" email notification.

Any advice?

CodePudding user response:

An order will have the status on-hold as long as the payment is not completed. To change the default order status for certain payment methods immediately to processing (and skip the on-hold status) and send the processing email notification, you can use:

  • Bacs - woocommerce_bacs_process_payment_order_status filter hook
  • Cheque - woocommerce_cheque_process_payment_order_status filter hook
  • Cod - woocommerce_cod_process_payment_order_status filter hook

So you get:

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

These filters cause the status to change to the desired status. The email notification will be sent automatically based on this

  • Related