Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

WooCommerce: Disable coupons on sale items only

Posted on August 19, 2025August 19, 2025 By Admin No Comments on WooCommerce: Disable coupons on sale items only

WooCommerce: Disable Coupons on Sale Items Only

If you want to prevent customers from using coupons on products that are already on sale, WooCommerce does not offer a built-in setting for this. The quick fix is to add a custom code snippet that disables coupon usage only when the cart contains sale items. This ensures discounts don’t stack, protecting your margins while still allowing coupons on regular-priced products.

Quick Fix: Disable Coupons on Sale Items with a Filter Snippet

add_filter( 'woocommerce_coupons_enabled', 'disable_coupons_on_sale_items', 10, 2 );
function disable_coupons_on_sale_items( $enabled, $cart ) {
    if ( ! is_admin() && $cart ) {
        foreach ( $cart->get_cart() as $cart_item ) {
            if ( $cart_item['data']->is_on_sale() ) {
                return false; // Disable coupons if any sale item is in the cart
            }
        }
    }
    return $enabled;
}

Why This Happens

WooCommerce’s coupon system applies discounts regardless of whether products are on sale. Many store owners want to avoid stacking discounts because:

  • It reduces profit margins excessively.
  • It can cause confusion with pricing and promotions.
  • It may violate promotional rules or terms.

By default, WooCommerce does not differentiate coupon applicability based on product sale status. The snippet above hooks into the coupon enablement process and disables coupons if any sale item is detected in the cart.

Step-by-Step: How to Disable Coupons on Sale Items Only

  1. Access your theme’s functions.php file or use a code snippets plugin.

    Editing functions.php is common, but using a plugin like “Code Snippets” is safer and easier to manage.

  2. Copy and paste the following code snippet:
add_filter( 'woocommerce_coupons_enabled', 'disable_coupons_on_sale_items', 10, 2 );
function disable_coupons_on_sale_items( $enabled, $cart ) {
    if ( ! is_admin() && $cart ) {
        foreach ( $cart->get_cart() as $cart_item ) {
            if ( $cart_item['data']->is_on_sale() ) {
                return false; // Disable coupons if any sale item is in the cart
            }
        }
    }
    return $enabled;
}
  1. Save the changes.
  2. Clear any caching plugins or server cache.

    This ensures the new code takes effect immediately.

  3. Test the functionality.

    Add a sale item to your cart and try applying a coupon. The coupon should be disabled. Then try with only regular-priced items to confirm coupons still work.

Testing

  1. Add a product on sale to your cart.
  2. Attempt to apply a valid coupon code.

    The coupon should not apply, and WooCommerce will typically show a message that coupons are disabled or invalid.

  3. Remove the sale item and add a regular-priced product.
  4. Apply the same coupon code again.

    This time, the coupon should apply successfully.

  5. Test with multiple items, mixing sale and regular products.

    Coupons should be disabled if any sale item is present.

Works on

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, DirectAdmin
WooCommerce Versions WooCommerce 3.0 and above (tested on latest versions)
WordPress Versions WordPress 5.0 and above

FAQ

  • Q: Can I disable coupons only on specific sale products?
    A: Yes, you can modify the snippet to check product IDs or categories before disabling coupons.
  • Q: Will this snippet affect admin users or backend coupon testing?
    A: No, the snippet excludes admin area checks, so coupons remain enabled in the backend.
  • Q: What if I want to allow coupons on sale items but limit the discount amount?
    A: You would need a more advanced custom function or a plugin that controls coupon discount rules.
  • Q: Can I combine this with other coupon restrictions?
    A: Yes, but ensure your custom code snippets do not conflict. Test thoroughly after adding multiple restrictions.
  • Q: Is there a plugin that does this without custom code?
    A: Some premium WooCommerce plugins offer advanced coupon restrictions, but the snippet is a lightweight and free solution.
WooCommerce How‑tos Tags:Coupons, Sales, WooCommerce

Post navigation

Previous Post: WooCommerce Stripe: pending payments stuck — causes & fixes
Next Post: WooCommerce: Add ‘Click & Collect’ without a plugin

Leave a Reply Cancel reply

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

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com