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

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

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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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');
}
}
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'); } }
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

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


0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
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.