Wooassist

Assistance for Your Woocommerce Store

  • How it Works
  • Pricing
  • Services
    • Site Maintenance
    • AI SEO and Content Marketing
  • Blog
    • How-To Articles
    • Code Snippets
    • SEO For E-Commerce
    • Theme and Plugin Reviews
    • Wooassist News
    • WordPress/WooCommerce News
    • Interviews
  • About Us
  • Contact
You are here: Home / Code Snippets / How to Use WooCommerce Coupons to Drive Sales; Includes Advanced Custom Enhancements

How to Use WooCommerce Coupons to Drive Sales; Includes Advanced Custom Enhancements

December 9, 2024 By Nick J Leave a Comment

WooCommerce is a powerful e-commerce platform that empowers businesses to create customizable online stores with ease. One of its most effective features for boosting sales and enhancing customer loyalty is the coupon system. Learning how to use WooCommerce coupons to drive sales can be advantageous to your business. It can also help increase traffic and build a loyal customer base.

What are the Benefits of Using WooCommerce Coupons?

WooCommerce coupons are promotional codes that customers can apply at checkout to receive discounts on their purchases. These discounts can take various forms, including percentage discounts, fixed-amount reductions, free shipping, and more. By strategically creating and using these coupons, you can achieve several key goals:

  • Drive Traffic: Attract new customers and encourage repeat visits.
  • Increase Sales: Motivate customers to make purchases or spend more.
  • Enhance Customer Loyalty: Reward loyal customers and increase their lifetime value.

Creating WooCommerce Coupons

How to Use WooCommerce Coupons to Drive Sales

To create coupons for your WooCommerce store, you can follow the steps below:

  1. Log in to Your WordPress Admin Area.
  2. Go to Marketing > Coupons.
  3. Click on Add Coupon to start creating your new coupon. You will be directed to a page where you can configure various settings for your coupon.
  4. Provide a name and an optional brief description of the coupon’s purpose. This is for your reference and will not be visible to customers.
  5. Enter a unique code that customers will use to redeem the coupon. This code should be easy to remember and relevant to the promotion.
  6. In the Coupon Data section, you’ll find several tabs where you can set detailed rules and restrictions, Once you’ve set these up, click on Publish and your coupon will be ready for use on your store.
  7. Important: Make sure you test your coupons so you know you’ve set them up correctly and do exactly what you want them to do.

Using WooCommerce Coupons Effectively

Promote Your Coupons

To maximize the impact of your coupons, you should promote them. Here are a few ways on how you can promote your coupons.

  • Email Marketing: Send personalized emails to your subscriber list with coupon codes and details.
  • Social Media: Share coupon codes on your social media platforms to reach a broader audience.
  • Website Banners: Display banners or pop-ups on your website to inform visitors about current promotions.
  • Partnerships: Collaborate with influencers or other businesses to distribute your coupon codes.

Monitor Coupon Performance

Track the performance of your coupons to understand their impact and make data-driven decisions:

  • Use WooCommerce Reports: Access built-in reports to analyze coupon usage, sales, and customer behavior.
  • Google Analytics Integration: Integrate with Google Analytics to gain deeper insights into coupon performance and customer interactions.

Adjust Your Strategies

Based on performance data, you can adjust your coupon strategies to optimize results:

  • A/B Testing: Experiment with different coupon types, discount amounts, and promotional strategies to see what works best.
  • Seasonal Campaigns: Create seasonal or holiday-specific coupons to take advantage of peak shopping periods.
  • Loyalty Programs: Implement loyalty programs where customers earn points or rewards that can be redeemed for coupons.

Enhancing Customer Loyalty with Coupons

Enhancing Custom Loyalty

Coupons can be a powerful tool for fostering customer loyalty:

  • Welcome Offers: Give new customers a welcome coupon to encourage their first purchase. Even if you take a net loss on a customer’s first purchase, you can make up for it if they become a customer for life.
  • Birthday Discounts: Send personalized birthday coupons to make customers feel valued.
  • Referral Bonuses: Offer coupons to customers who refer friends or family to your store.

Enhancing WooCommerce Coupons

While WooCommerce offers a robust coupon system out of the box, there are times when you might need more advanced functionalities to meet specific business goals. By adding custom code snippets to your WooCommerce store, you can expand the capabilities of coupons to offer unique promotions, automate discounts, and better target your customer segments.

Below are several ways to enhance WooCommerce coupons with custom code, along with practical use cases for each enhancement.

Important: Before implementing any custom code, always back up your site and test changes in a staging environment. Use a child theme or a custom plugin to add code snippets to prevent them from being overwritten during theme updates.

Restrict Coupons to First-Time Customers

Objective: Encourage new customer acquisition by offering exclusive discounts to first-time buyers.

Use-Case: Offer a “10% off” coupon to customers making their first purchase to incentivize them to complete their initial order.

Implementation

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_coupon_is_valid', 'restrict_coupon_to_first_time_customers', 10, 2);
function restrict_coupon_to_first_time_customers($valid, $coupon) {
    if ($coupon->get_code() === 'NEWCUSTOMER') {
        $user_orders = wc_get_orders(array(
            'customer_id' => get_current_user_id(),
            'limit'       => 1,
        ));

        if (!empty($user_orders)) {
            throw new Exception(__('This coupon is only valid for first-time customers.', 'woocommerce'));
        }
    }
    return $valid;
}

Explanation

  • Coupon Code Check: The code checks if the applied coupon code is NEWCUSTOMER.
  • Order History Verification: It retrieves any existing orders associated with the current user.
  • Validation: If the user has previous orders, an error message is displayed, and the coupon becomes invalid for them.

Automatically Apply a Coupon Based on Cart Value

Objective: Increase the average order value by automatically applying a discount when the cart total exceeds a certain amount.

Use-Case: Offer free shipping or a discount when customers spend over $100 without requiring them to enter a coupon code.

Implementation

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_before_calculate_totals', 'apply_coupon_based_on_cart_total');
function apply_coupon_based_on_cart_total($cart) {
    if (is_admin() || !did_action('wp_loaded') || !is_checkout()) {
        return;
    }

    $coupon_code = 'FREESHIP100'; // Your coupon code
    $threshold = 100; // Threshold amount for applying the coupon

    if ($cart->subtotal >= $threshold && !WC()->cart->has_discount($coupon_code)) {
        WC()->cart->apply_coupon($coupon_code);
    } elseif ($cart->subtotal < $threshold && WC()->cart->has_discount($coupon_code)) {
        WC()->cart->remove_coupon($coupon_code);
    }
}

In addition, the code below will add an alert so you can urge customers to add more products to their cart so they can get the discount.

add_action('woocommerce_before_cart', 'notify_customer_of_threshold');
add_action('woocommerce_before_checkout_form', 'notify_customer_of_threshold');

function notify_customer_of_threshold() {
    $coupon_code = 'FREESHIP100'; // Your coupon code
    $threshold = 100; // Threshold amount for the coupon to apply
    $current_total = WC()->cart->subtotal;

    if ($current_total > 0 && $current_total < $threshold) {
        $amount_needed = $threshold - $current_total;
        wc_print_notice(
            sprintf(
                __('Add %s more to your cart to qualify for free shipping!', 'woocommerce'),
                wc_price($amount_needed)
            ),
            'notice'
        );
    }
}

Restrict Coupon Usage to Specific User Roles

Objective: Offer exclusive promotions to certain customer groups, such as wholesale buyers or VIP members.

Use-Case: Provide a special discount to users with the wholesale_customer role.

Implementation

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_coupon_is_valid', 'restrict_coupon_to_user_roles', 10, 2);
function restrict_coupon_to_user_roles($valid, $coupon) {
    if ($coupon->get_code() === 'WHOLESALE10') {
        $allowed_roles = array('wholesale_customer');
        $current_user  = wp_get_current_user();

        if (!array_intersect($allowed_roles, $current_user->roles)) {
            throw new Exception(__('This coupon is not valid for your account type.', 'woocommerce'));
        }
    }
    return $valid;
}

Explanation

  • Role Verification: Checks if the current user has one of the allowed roles.
  • Error Handling: If not, it throws an exception and invalidates the coupon.

Add a Minimum Product Quantity Requirement

Objective: Encourage bulk purchases by requiring a minimum quantity of items in the cart to use a coupon.

Use-Case: Offer a discount when customers buy 10 or more items.

Implementation:

Restrict Coupon Usage Based on Minimum Product Quantity

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_coupon_is_valid', 'restrict_coupon_to_minimum_quantity', 10, 2);
function restrict_coupon_to_minimum_quantity($valid, $coupon) {
    if ($coupon->get_code() === 'BULKBUY') {
        $required_quantity = 10;
        $cart_quantity     = WC()->cart->get_cart_contents_count();

        if ($cart_quantity < $required_quantity) {
            throw new Exception(sprintf(__('You need to purchase at least %d items to use this coupon.', 'woocommerce'), $required_quantity));
        }
    }
    return $valid;
}


Explanation
  • Function: The restrict_coupon_to_minimum_quantity function validates the coupon by checking if the cart quantity meets the minimum required.
  • Exception Handling: If the cart quantity is less than the required amount, an exception is thrown with a helpful message, preventing the coupon from being applied.
Display an Alert to Customers to Add More Products

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_before_cart', 'notify_customer_of_quantity_threshold');
add_action('woocommerce_before_checkout_form', 'notify_customer_of_quantity_threshold');

function notify_customer_of_quantity_threshold() {
    $coupon_code       = 'BULKBUY';     // Your coupon code
    $required_quantity = 10;            // Minimum quantity required
    $cart_quantity     = WC()->cart->get_cart_contents_count();

    // Check if the coupon is not applied and cart quantity is less than required
    if ($cart_quantity > 0 && $cart_quantity < $required_quantity && !WC()->cart->has_discount($coupon_code)) {
        $quantity_needed = $required_quantity - $cart_quantity;
        wc_print_notice(
            sprintf(
                __('Add %d more item(s) to your cart to qualify for the BULKBUY discount!', 'woocommerce'),
                $quantity_needed
            ),
            'notice'
        );
    }
}

Explanation

  • Function: The notify_customer_of_quantity_threshold function displays a notice on the cart and checkout pages when the cart quantity is below the required minimum.
  • Conditions:
    • Checks if the cart is not empty.
    • Verifies that the cart quantity is less than the required quantity.
    • Ensures the coupon isn’t already applied.
  • Message: Displays how many more items the customer needs to add to qualify for the discount.
Optional: Automatically Apply the Coupon When Quantity Requirement Is Met

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_before_calculate_totals', 'apply_coupon_based_on_quantity');
function apply_coupon_based_on_quantity($cart) {
    if (is_admin() || !did_action('wp_loaded')) {
        return;
    }

    $coupon_code       = 'BULKBUY';     // Your coupon code
    $required_quantity = 10;            // Minimum quantity required
    $cart_quantity     = $cart->get_cart_contents_count();

    if ($cart_quantity >= $required_quantity && !WC()->cart->has_discount($coupon_code)) {
        WC()->cart->apply_coupon($coupon_code);
    } elseif ($cart_quantity < $required_quantity && WC()->cart->has_discount($coupon_code)) {
        WC()->cart->remove_coupon($coupon_code);
    }
}

Explanation

  • Function: The apply_coupon_based_on_quantity function automatically applies or removes the coupon based on the cart quantity.
  • Conditions:
    • Applies the coupon when the cart quantity meets or exceeds the required amount.
    • Removes the coupon if the cart quantity falls below the required amount.

Automatically Apply a Coupon When Specific Products Are in the Cart

Objective: Simplify the user experience by auto-applying coupons when certain products or categories are added to the cart.

Use-Case: During a promotion, automatically apply a discount when customers add products from the “Summer Sale” category to their cart.

Implementation

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_before_calculate_totals', 'apply_coupon_for_specific_categories');
function apply_coupon_for_specific_categories($cart) {
    if (is_admin() || !did_action('wp_loaded')) {
        return;
    }

    $coupon_code       = 'SUMMER20';       // Your coupon code
    $target_categories = array('summer-sale'); // Category slugs
    $apply_coupon      = false;

    foreach ($cart->get_cart() as $cart_item) {
        $product_id = $cart_item['product_id'];
        $terms      = get_the_terms($product_id, 'product_cat');

        if ($terms && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                if (in_array($term->slug, $target_categories)) {
                    $apply_coupon = true;
                    break 2;
                }
            }
        }
    }

    if ($apply_coupon && !WC()->cart->has_discount($coupon_code)) {
        WC()->cart->apply_coupon($coupon_code);
    } elseif (!$apply_coupon && WC()->cart->has_discount($coupon_code)) {
        WC()->cart->remove_coupon($coupon_code);
    }
}

Explanation

  • Category Check: Iterates through cart items to check if any belong to the specified categories.
  • Automatic Application/Removal: Applies or removes the coupon based on whether the condition is met.

Set Coupons to Expire Automatically After Use

Objective: Limit a coupon to a single use per customer and ensure it expires immediately after being used.

Use-Case: Send personalized one-time-use coupons to customers as part of a special promotion.

Implementation:

Add the following code snippet to your theme’s functions.php file or a custom plugin:

add_action('woocommerce_applied_coupon', 'expire_coupon_after_single_use');
function expire_coupon_after_single_use($coupon_code) {
    $coupon = new WC_Coupon($coupon_code);

    if ($coupon->get_usage_limit_per_user() == 1) {
        $coupon->set_date_expires(current_time('mysql'));
        $coupon->save();
    }
}

Explanation:

  • Usage Limit Check: Verifies if the coupon is limited to one use per user.
  • Expiration Setting: Sets the coupon’s expiration date to the current time after it’s applied.

Unlocking the Full Potential of WooCommerce Coupons

By integrating these advanced coupon strategies into your WooCommerce store, you’re not just offering discounts—you’re creating personalized shopping experiences that can significantly boost sales and foster long-term customer loyalty. All these customizations transform your promotional efforts into powerful marketing tools. Remember to back up your site before making any changes and thoroughly test each new feature in a staging environment. As you continue to monitor performance and adapt your strategies, you’ll unlock the full potential of WooCommerce coupons to drive growth and success for your online business.

People that read this article also liked

How to Change Checkout Form Heading in WooCommerce How to Rename Primary Menu in Mobile View for Storefront Theme How to Remove Horizontal Line under Page Title in Storefront Theme How to Move the Navigation Menu Outside of Header for Storefront

Filed Under: Code Snippets, How-To Articles

Leave a Reply Cancel reply

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


Woocommerce Support

wooassist-team-in-Iloilo

Get 2 Hours of
FREE SUPPORT

We are so confident that you will love our services that we will give you your first 4 hours at a 50% discount

That's 4 hours for only $75

BUY NOW

Happy Wooassist Customers

Awesome! Fantastic! I just went to our site and I see that our site has been fixed!! We are getting orders again thanks to you all at WooAssist! Our site has not worked and looked this good for many months!! You all are awesome! Thank you so much for fixing our site! You have a customer for life! Thanks for making my day wonderful!

Kenneth Arnold

We have been quite pleased working with WooAssist as they help fill in the gaps of our development needs, all at a great price. They are always timely and communicate great, I highly recommend their services.

James Grasty

My husband and I am EXTREMELY pleased with the WooAssist Team. They provide excellent service, are very knowledgeable, and super easy to communicate with. The team ALWAYS has our company's best interests in mind. I love WooAssist! All of you make my job easier.

Jennifer Taft leetaft.com

Categories

  • Code Snippets
  • How-To Articles
  • Interviews
  • SEO For E-Commerce
  • Theme and Plugin Reviews
  • Uncategorized
  • Wooassist News
  • WordPress/WooCommerce News

Recent Posts

  • How to Use WooCommerce Coupons to Drive Sales; Includes Advanced Custom Enhancements
  • How to Implement WooCommerce Reviews and Ratings: Encouraging Customer Feedback and Building Trust
  • Focus on Your Business: Let Wooassist Handle Your WordPress and WooCommerce Site Updates
  • Maximizing Your Content’s Reach and Impact with Content Promotion
  • Content Marketing Best Practices for Optimizing Local Search Results
Let us support your online store so you can manage your business

Get started today

Get 2 Hours of FREE SUPPORT

We are so confident that you will love our services that we will give you your first 4 hours at a 50% discount

That's 4 hours for only $75

BUY NOW

Free eBook

Your subscription could not be saved. Please try again.
Your subscription has been successful.

YOURS FREE!

5 Things Every Online Store Can Fix On Their Website In The Next Week To Increase Sales

Quick Links

  • How it Works
  • Pricing
  • Blog
  • Contact
  • About Wooassist
  • My Account
  • Checkout
  • Privacy Policy
  • Cookie Policy
  • Terms and Conditions

Wooassist

Australia:
59 Luke St.
Hemmant QLD 4174

Philippines:
San Miguel St.
Poblacion, Iligan City 9200

Connect

     

Copyright © 2025 · Wooassist

Yours FREE!

5 Things Every Online Store Can Fix On Their Website In The Next Week To Increase Sales