Try for a week – risk free!

Insights on discount codes and coupons for Shopify store owners

Expert guides on managing Shopify discounts and protecting your profits from coupon extensions like Honey and Capital One Shopping. Learn to prevent discount abuse while maintaining effective promotions.

⟻ View all articles

How to Block Discount Codes During Sales (Without Losing Your Mind)

Here's a fun problem: You're running a killer Black Friday sale, but you've got discount codes floating around like confetti at a parade. There's your newsletter subscriber codes, your affiliate partner codes, your sorry-we-messed-up-your-order codes, those Instagram influencer codes that somehow never expire, and that FLASH50 code from last summer that's still circulating on deal-hunting forums (you know the ones).

Next thing you know, customers are stacking discounts like they're playing Jenga, and your margins are getting destroyed.

Let's fix that?

Fix the Problem at Its Source

Let's be real - if you're reading this article, you've probably been creating discount codes without restrictions. We've all been there. Just tossing up discount codes without limiting which products they apply to. It's faster in the moment, but it's causing you headaches now.

Here's my suggestion: Make a product collection called 'Allows Discounts' and ensure all discount codes you create from here out target that collection. Then, in the future, you can simply adjust the products in that collection if you ever need to adjust which products are affected by discounts.

Got thousands of incorrectly created codes already? No worries - the solutions below will help you handle your current mess while you work on fixing your discount strategy for the future.

The Hard Fix

Look, we could just deactivate discount codes during sales and reactivate them later. But let's be real - that's like putting a band-aid on a broken arm.

Here's what we're actually going to do: Convert your Amount off order discount codes into Amount off products discounts. Why? Because with product-level discounts, you can target specific collections instead of your entire store. And since collections are dynamic (meaning you can add or remove products whenever), you'll finally have the flexibility to control what gets discounted without breaking existing codes. Game changer.

  1. First, get the data. Head to Analytics > Reports in your Shopify admin and create a custom report for the last 90 days of orders. Include the discount codes used and their frequency. This tells you which codes you actually need to care about.
    Pro tip:

    If you're using Omnipotent (shameless plug, I know), you've already got these reports ready to go. Plus, it has this neat "Dangerous Discounts" feature that's saved more than a few stores from disaster. It flags those forgotten discount codes with high discount rates that are just sitting there waiting to be discovered - you know, like that 99% off code your dev made while testing last year, or that employee discount that Chad from marketing still has even though he left six months ago. The kind of codes that make your accountant cry if they ever leak.

  2. Play detective with those codes. Are they coming from:
    • Your affiliate app spitting them out automatically?
    • That influencer program you set up last summer?
    • Your VA creating them manually?
    • That marketing app you installed and forgot about?
  3. Time for the fix. Remember that 'Allows Discounts' collection we talked about earlier? Here's how to use it:
    • For app-generated codes: Check your app settings. Most modern Shopify apps have collection targeting options. Set them to use your 'Allows Discounts' collection.
    • For manually created codes: Sorry friend, you'll need to recreate these properly. But hey, better now than during BFCM madness.
  4. The cleanup:
    • If they're manual codes: Deactivate the old ones, create new ones targeting your 'Allows Discounts' collection.
    • If they're app-generated: Update the app settings first, then have it regenerate fresh codes. This is especially important for affiliate or commission-based codes where tracking matters.

Yes, this is more work upfront. But it's like cleaning your room - painful now, heavenly later.

The Automatic, Get Home By 3 PM Fix

Quick heads up: You'll need to be on Shopify Plus to use these solutions. Not on Plus? The hard fix above is your best bet for now. But if you've got Plus, let's make some magic happen.

Let's break this down into a few approaches, from dead simple to slightly less simple.

The Nuclear Option (Block Everything)

This is the "I don't have time for this" solution. Simple, brutal, effective:

if Input.cart.discount_code
  Input.cart.discount_code.reject(
    message: "Sorry, discount codes are taking a break during our sale."
  )
end

Output.cart = Input.cart

The Selective Blocker

Want to be a bit more surgical about it? Here's how to block specific codes:

unallowed_discount_codes = ['SUMMER2024', 'WELCOME10', 'VIP20']

if Input.cart.discount_code
  if unallowed_discount_codes.include?(Input.cart.discount_code.code)
    Input.cart.discount_code.reject(
      message: "That code's taking a vacation during our sale."
    )
  end
end

Output.cart = Input.cart

The VIP Treatment

Or flip it around - only allow certain codes:

allowed_discount_codes = ['BLACKFRIDAY', 'CYBERMONDAY']

if Input.cart.discount_code
  unless allowed_discount_codes.include?(Input.cart.discount_code.code)
    Input.cart.discount_code.reject(
      message: "Only special sale codes work right now. Nice try though!"
    )
  end
end

Output.cart = Input.cart

Setting This Up

  1. Install the Shopify Script Editor app
  2. Make a new Line Items script
  3. Pick the blank template
  4. Copy/paste whichever code above matches your needs
  5. Test it in preview mode (seriously, test it)

Already have Shopify Scripts installed with an active line item script? No problem. Just add the snippet at the end of your existing script.

Block Discounts for Specific Products

Here's where things get interesting. Let's say you want to block discount codes when someone has a specific product in their cart:

# Block discount codes for products tagged with 'no-discounts'
Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  next if product.gift_card?
  
  if product.tags.include?('no-discounts')
    if Input.cart.discount_code
      Input.cart.discount_code.reject(
        message: "Some items in your cart aren't eligible for additional discounts"
      )
    end
    break
  end
end

Output.cart = Input.cart

Quick heads up: This is an all-or-nothing deal. If someone has a mix of regular products and "no-discounts" products in their cart, the discount code gets rejected for everything. That's just how Shopify Scripts work - you can't selectively apply discounts to specific products.

Need that kind of selective discount power? Set up your discount codes properly in the Shopify admin instead. Create a collection called "Allows-Discounts" (or whatever makes sense to you) and make your discount codes only work with that collection. Way cleaner.

Schedule It

Don't want to stay up until 12:00am the night before you sale to push the Shopify Script live? You can use Shopify's Launchpad app to schedule the publication of your script if you're feeling brave.

Wrap Up

That's it! You've got what you need to lock down those discount codes during your sale. Test everything thoroughly before your sale kicks off - BFCM is stressful enough without debugging discount code issues.

Good luck with your sale! May your conversion rates be high and your support tickets low.

One More Thing...

If this article was relevant to you, there's a decent chance your store is battling discount abuse. You know - those fun moments when coupon sites like Honey, RetailMeNot, and Capital One Shopping decide to leak your discount codes to the world. Since you're already thinking about discount code management, check out Omnipotent. We built it specifically to help Shopify stores fight back against these coupon sites that automate discount code testing and sharing. Simple, bootleg-free solution to a pretty annoying problem.

Check out Omnipotent in the Shopify App Store