Providing autocomplete orders for coupon eliminates manual order processing thereby saving time for both customers and WooCommerce Store owners. Since the order gets completed almost instantly, using coupons becomes very convenient for the shoppers and it also encourages them to come back and shop again. Let’s see how to utliize autocompleting orders when a coupon is used in your WooCommerce store via WooCommerce customization.
Solution: Autocomplete Orders When a Coupon is Used
This code ensures that orders are automatically marked as ‘completed’ when coupons are applied during checkout.
add_action('woocommerce_checkout_update_order_meta', 'ts_custom_woocommerce_auto_complete_order'); function ts_custom_woocommerce_auto_complete_order($order_id) { if (!$order_id) { return; } $order = wc_get_order($order_id); // Check if any coupons have been applied to the order $applied_coupons = $order->get_coupon_codes(); if (!empty($applied_coupons) && $order->get_total() > 0) { // If coupons are applied and the order total is greater than 0, complete the order $order->update_status('completed'); } }
Output
When a customer applies any coupon during checkout, then those orders will be automatically set to the ‘completed’ status.
Just like the autocompletion feature for order status, you can also customize the order status based on the total amount of the order. This customization ensures that orders are changed to ‘processing’ status based on order value.