Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Autocomplete Orders When a Coupon is Used in WooCommerce?

Providing autocomplete orders for coupons 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.

How to Autocomplete Orders When a Coupon is Used in WooCommerce? - Tyche Softwares

Autocomplete Orders for a Specific Coupon in WooCommerce

If you run multiple promotions in your WooCommerce store, you might want orders to be automatically completed only when a specific coupon code is used. Doing this reduces manual checks and speeds up the order flow for trusted promotions.

 In this guide, we’ll show you how to automatically complete WooCommerce orders only when a specific coupon is applied.

add_action('woocommerce_checkout_update_order_meta', 'ts_autocomplete_specific_coupon_order');
function ts_autocomplete_specific_coupon_order($order_id) {
    if (!$order_id) {
        return;
    }

    $order = wc_get_order($order_id);
    $applied_coupons = $order->get_coupon_codes();

    // Define the specific coupon code
    $specific_coupon = 'DISCOUNT10'; // Change this to your coupon code

    // Check if the specific coupon is applied
    if (in_array($specific_coupon, $applied_coupons) && $order->get_total() > 0) {
        $order->update_status('completed');
    }
}

Output

When a customer applies the coupon code DISCOUNT10 during checkout, the order is automatically marked as Completed status after checkout.

On the order confirmation page shown below, you can see Cash on Delivery as the payment method, and the DISCOUNT10 coupon is applied.

How to Autocomplete Orders When a Coupon is Used in WooCommerce? - Tyche Softwares

Let’s go to the WooCommerce → Orders page, and the same order is marked with the status set to Completed instead of the default Processing order status.

Autocomplete Orders when a coupon is used

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
2 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Bram
3 months ago

How would you change this, if you only want to auto-complete it when a specific coupon is used? Or better even, when one of the coupons is used where you want it to auto-complete.

Last edited 3 months ago by Bram
2
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.