1
votes

In Woocommerce, when the payment option is COD, the orders go directly to the "Processing" state.

https://docs.woocommerce.com/document/managing-orders/#prettyPhoto

Source: https://docs.woocommerce.com/document/managing-orders/#prettyPhoto

I need this to work like this, except when the client's role is "X".

I have seen that this can be solved with this code:

function cod_payment_method_order_status_to_onhold( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    if (  get_post_meta($order->id, '_payment_method', true) == 'cod' )
        $order->update_status( 'on-hold' );
}

add_action( 'woocommerce_thankyou', 'cod_payment_method_order_status_to_onhold', 10, 1 );

However, the problem is that it goes through "Processing", sends the email and then goes to "on hold". I want to avoid sending the "Processing" mail

Any way to do it? Thank you!

1

1 Answers

1
votes

You should better use woocommerce_cod_process_payment_order_status dedicated filter hook. You will have to replace "administrator" user role by your "X" role.

The hooked function code:

add_filter( 'woocommerce_cod_process_payment_order_status', 'set_cod_process_payment_order_status_on_hold', 10, 2 );
function set_cod_process_payment_order_status_on_hold( $status, $order ) {
    $user_data = get_userdata( $order->get_customer_id() );
    if( ! in_array( 'administrator', $user_data->roles ) )
        return 'on-hold';
    return $status;
}

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