phpwordpresswoocommerceorderspayment-method

Change orders status made with cheque payment method to "processing" status


I need to make WooCommerce push payments made by check into the "processing" status rather than the "on hold" status. I tried the snippet below however it doesn't seem to have an effect.

Here is my code:

add_filter( 'woocommerce_payment_complete_order_status', 'sf_wc_autocomplete_paid_orders' );

function sf_wc_autocomplete_paid_orders( $order_status, $order_id ) {

$order = wc_get_order( $order_id );

if ($order->status == 'on-hold') {
    return 'processing';
}

return $order_status;
}

How can I achieve this?

Thanks.


Solution

  • Here is the function you are looking at hooked in woocommerce_thankyou hook:

    add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
    function cheque_payment_method_order_status_to_processing( $order_id ) {
        if ( ! $order_id )
            return;
    
        $order = wc_get_order( $order_id );
    
        // Updating order status to processing for orders delivered with Cheque payment methods.
        if ( $order->get_payment_method() === 'cheque' ) {
            $order->update_status( 'processing' );
        }
    }
    

    This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    This is tested and works.


    Related thread: WooCommerce: Auto complete paid orders