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 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.

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
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x