Reputation: 163
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
Upvotes: 2
Views: 4417
Reputation: 185
Use woocommerce_order_status_processing in trigger! woocommerce_thankyou is called only in direct checkout proccess
Upvotes: 2
Reputation: 1955
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
Upvotes: 6