code snippets wordpress

How to Automatically Complete Orders in WooCommerce

Last Updated on April 24, 2022 by WP Knowledge Hub

Manually add this code to your child theme’s functions.php file or you can also do it by using a code snippets plugin, but it’s best to avoid adding extra plugins if it’s not absolutely necessary. Make sure you don’t add any custom code directly to your parent theme’s functions.php file as this will be deleted when you update the theme.

In this example, we set to order to “Completed”, but you could also change the “Completed” status to be another order status, like “Processing”.

/**
* Function to auto complete new WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'new_woocommerce_auto_complete_order' );
function new_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}