'Auto change order status from processing to completed in Woocommerce
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
Solution 1:[1]
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
Solution 2:[2]
Use woocommerce_order_status_processing in trigger! woocommerce_thankyou is called only in direct checkout proccess
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | developerme |
Solution 2 | Diogenes Oliveira Junior |