0
votes

I want to change every order from woocommerce if the 'PROCESSING' status will automatically be updated to 'COMPLETED'.

I have tried writing the function in functions.php file but I did not succeed.

How can I automatically change the order status from "processing" to "completed" in Woocommerce when I have received payment from the user?

I use this code but it has no effect


    add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) { 
        if ( ! $order_id ) {
            return;
        }

        $order = wc_get_order( $order_id );
        if( $order->has_status( 'processing' ) ) 
        {
            $order->update_status( 'completed' );
        }
    }

Thank's

1
when you want to convert processing to completed? At thank you page or do you want to run one cron job?dipmala
The below answer is working for you ?developerme
@prateik-darji it doesn't work for me. do you have another solution?Dimas Anugerah
@dipmala when I have received payment from the userDimas Anugerah

1 Answers

4
votes

To auto completed orders, you should try the following:

add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
    function custom_woocommerce_auto_complete_order( $order_id ) { 
        if ( ! $order_id ) {
            return;
        }

        $order = wc_get_order( $order_id );

        if( $order->has_status( 'processing' ) ) {
            $order->update_status( 'completed' );
        }
    }

Code goes in function.php file of your active child theme (or theme).I have tested the code and its working for me please check screenshot https://prnt.sc/m3zrwp