user7031052
user7031052

Reputation:

Change Woocommerce order status for Cash on delivery

I need to change the default order status that Woocommerce is applying to orders which are paid by Cash on delivery. The default is processing and I need to set it to on-hold. 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's not working. Any thoughts?

Upvotes: 1

Views: 3794

Answers (2)

hadi ur rehman
hadi ur rehman

Reputation: 71

this solved my problem

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('on-hold');
}

put this in your functions.php

Upvotes: 5

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

To resolve the issue please use below code:

add_action( 'woocommerce_thankyou', 'wc_change_status' );
function wc_change_status( $order ) {

        $order = new WC_Order($order);
        $order->update_status('on-hold', 'This is the change status');
        //print('<pre>');
      //  print_r($order);
       }

Upvotes: -1

Related Questions