Support » Plugin: WooCommerce » Default cash on delivery status

  • Hi,
    I need the defaut order status for cash on delivery changed from “processing” to “pending”. I have tried this

      add_action( 'woocommerce_thankyou', 'my_order_status', 50 );
        function my_order_status( $order_id ) {
        if ( ! $order_id ) {
        return;
        }
        $order = wc_get_order( $order_id );
        if ( ( get_post_meta( $order->id, '_payment_method', true ) == 'cod'  ) && ( $order->status == 'processing' ) ) {
        $order->update_status('on-hold');
        }
        }

    but it did not work. Does anyone know how to achieve this?
    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The order status should have been checked like below:

    $order->post_status === 'wc-processing'

    Below is the complete corrected code:

    
    add_action( 'woocommerce_thankyou', 'my_order_status', 10, 1 );
    function my_order_status( $order_id ) {
    	if ( ! $order_id ) {
    		return;
    	}
    	$order = wc_get_order( $order_id );
    	if ( ( get_post_meta( $order->id, '_payment_method', true ) === "cod"  ) && ( $order->post_status === 'wc-processing' ) ) {
    		$order->update_status('on-hold');
    	}
    }

    I hope this helps 🙂

    • This reply was modified 5 years, 2 months ago by Prasad Nevase.
    Thread Starter bggg12

    (@bggg12)

    Hi,
    thank you so much for replying. Unfortunately the status is still “processing”…

    Did you place the second code block in your there’s functions.php file? Also do note that it will only work for new orders. It won’t update status for old orders which have cod payment method.

    Thread Starter bggg12

    (@bggg12)

    Yes, I did place your new code in my childd theme’s funcctions and placed a new order which camee in as “processing”…

    I double checked and its working for me with default theme and WooCommerce as only active plugin. Probably you may try changing the priority of the hook.

    Thread Starter bggg12

    (@bggg12)

    Sorry, it’s not working for me but I think it might be due to a plugin…

    Maybe this works:

    // change COD payment method order status from processing to on-hold
    add_action('woocommerce_thankyou_cod', 'action_woocommerce_thankyou_cod', 10, 1);
    function action_woocommerce_thankyou_cod($order_id)
    {
    	$order = wc_get_order($order_id);
    	$order->update_status('pending');
    }

    @harkalygergo

    I used your code in my themes custom functions, and it worked as expected. Thanks. (I used status ‘completed’ for COD (otherwise I will have to add that status manually after delivery).

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Default cash on delivery status’ is closed to new replies.