Want to know what WordPress Theme a site is using? Check Out Now!

How to Autocomplete WooCommerce Orders in WordPress? (Without Plugin)

Do you know when someone purchases a product from your WooCommerce website, the order status remains pending even after the payment?

Yes! By default, the order status stays pending in WooCommerce until you manually approve the order.

This leads to a bad user experience as users may have to wait hours to receive the order confirmation and access the product if you or your team are not available.

Autocompleting WooCommerce orders is a foolproof solution to avoid any such experiences for your website customers. All you need to do is to add the below code to your theme’s functions.php file.

/**
 * Auto Complete all WooCommerce orders.
 */
function maverick_woocommerce_auto_complete_order($order_id)
{
	if (!$order_id) {
		return;
	}

	$order = wc_get_order($order_id);
	$order->update_status('completed');
}

add_action('woocommerce_thankyou', 'maverick_woocommerce_auto_complete_order');

You can also use the code below to achieve the same.

/**
 * Auto Complete all WooCommerce orders.
 */
function maverick_auto_complete_paid_order( $status, $order_id, $order ) {
    return 'completed';
}

add_action( 'woocommerce_payment_complete_order_status', 'maverick_auto_complete_paid_order', 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *