skip to Main Content

How to change in woocommerce order status from processing to completed
?

I found snippet, but it only changes status if you go to thank you page, but if my customer decides just to close paypal page and don’t go to thank you page ?

Then it is still processing, tested it already. I need automatically to detect processing status and change it to processing.

2

Answers


  1. This will check for when the order changes status. If the status changes to processing, it will set the status to completed. Note that it does go through processing, so the user will probably get two emails back to back. You can disable one of the emails in the WC settings dashboard.

    function wc_status_change($order_id,$old_status,$new_status) {
       $order = new WC_Order( $order_id );
       if($order->status == 'processing'){
           $order->update_status('completed');
       }
    }
    
    Login or Signup to reply.
  2. In your case you have two options the first may not work as it is related to previous versions of woocommerce but the second one should work

    add the code to your functions.php

    add_filter( 'woocommerce_payment_complete_order_status', 'update_order_status_woo', 10, 2 );
    function update_order_status_woo( $order_status, $order_id ) {
    
        $order = new WC_Order( $order_id );
        if ( $order_status == 'processing' && ( 'on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status ) ) {
            return 'completed';
        }
        return $order_status;
    }
    

    add_action('woocommerce_order_status_changed', 'auto_update_processing_to_complete');
    
    function auto_update_processing_to_complete($order_id)
    {
        if ( ! $order_id ) {
            return;
        }
    
        $order = wc_get_order( $order_id );
        if ($order->data['status'] == 'processing') {
            $order->update_status( 'completed' );
        }   
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search