Reject Discount Codes at Shopify Checkout When Conditions Aren't Met
Influencer codes used by strangers, first-order codes used by repeat buyers, codes stacked on sale items. Here is how to stop discount codes from applying when your conditions are not met.

Discount codes travel. A code you created for your staff ends up on a coupon site. A 20% welcome code meant for first orders gets used by customers on their fifth purchase. An influencer code gets stacked on top of items that are already on sale. Each case is small on its own, but together they quietly eat margin.
The fix is to make codes only work under the conditions you intended. Shopify gives you a lot of control natively, and for the cases it does not cover, you can use checkout validation to stop the order with a clear message. This guide walks through both layers.
Why it matters
Discount leakage is hard to see because the cost is buried in average discount per order. But the impact is real:
- Margin loss on orders that would have happened at full price anyway.
- Unfair treatment of customers who play by the rules.
- Skewed attribution. If anyone can use an influencer code, you cannot tell which sales the influencer actually drove.
- Promo abuse at scale. Leaked codes attract customers who only buy with discounts.
For a broader view of abuse patterns, see our guide on promo code abuse prevention.
Common scenarios
| Scenario | What should happen |
|---|---|
| Staff or influencer code used by an untagged customer | Code does not apply |
| Welcome code used by a returning customer | Code does not apply |
| Code applied to items already on sale | Code does not apply to those items |
| Code used for an order shipping to an excluded country | Checkout is blocked with a message |
Layer 1. Native discount settings
Always start here. Native settings are reliable, easy to audit, and give customers the standard "code not valid" experience. When you create or edit a discount in Discounts, review these settings.
Customer eligibility
You can limit a discount to specific customer segments or specific customers. Segments are powerful because they update automatically. Examples:
- A segment of customers tagged
stafffor staff codes. - A segment of customers tagged
influencer-partnerfor partner codes. - A segment of customers with zero orders for a welcome code.
When a customer outside the segment enters the code, Shopify will not apply it. One important detail: segment eligibility needs to know who the customer is, so it works best when the customer is logged in or identified by email at checkout.
Minimum requirements
Set a minimum purchase amount or minimum quantity so codes cannot be used on tiny orders.
Product and collection scope
Limit the discount to specific products or collections, or exclude collections. To keep codes off sale items, maintain a collection of discounted products and exclude it, or scope the discount to a full-price collection.
Combinations
Control whether the code can combine with product, order, or shipping discounts. This prevents stacking a code on top of an automatic sale.
Usage limits
Limit total uses, enable "one use per customer", and give every campaign code an end date.
Layer 2. Checkout validation
Native settings cover most cases, but not all. Examples that often need more logic:
- Blocking a code for orders shipping to certain countries or regions.
- Rules based on cart contents beyond simple collection scope, such as "not valid if the cart contains a gift card or a bundle".
- Rules that combine customer tags with cart value or product type.
- Codes created by another app where you cannot change the eligibility settings.
For these, use a Cart and Checkout Validation function. Validation functions run server-side at checkout and can block the customer from completing the order, showing an error message you write. Public apps using validation functions work on all plans; custom apps generally need Shopify Plus.
The logic looks something like this:
if a discount code is applied
and the code is in the restricted list
and the shipping country is not in the allowed list:
block checkout with message:
"This code is only valid for orders shipping within the US. Remove it to continue."
What data a function can read depends on the API version and the fields it requests, so test how discount information is exposed before relying on a rule. If the condition is about who gets a discount, a custom discount function that simply does not apply the discount can be a softer alternative to blocking.
Step-by-step setup
- Audit your active codes. List every live code, its purpose, and who it is meant for.
- Fix what native settings can fix. Add customer segments, exclusions, combination limits, usage limits, and end dates.
- List the remaining gaps. Write each one as a rule: "Code X should not work when Y."
- Write clear error messages. Each message should say why and what to do, for example "Remove the code to continue" or "Log in to your partner account".
- Add validation rules for the gaps, either through an app or a custom function.
- Test both sides. Test as an eligible customer and as an ineligible one, logged in and logged out, and with express checkout.
Concrete examples
Staff code used by the public
Create a segment of customers tagged staff and restrict the code to it. If the code was created by an app that does not support segments, add a validation rule that blocks checkout when the code is applied and the customer is not tagged staff. Our guide on blocking checkout by customer tag covers the tag side in detail.
First-order code used by a returning customer
Restrict the code to a segment of customers with zero orders and set one use per customer. Keep in mind that a returning customer can still check out as a guest with a new email. For high-value welcome offers, pair this with fraud screening.
Code on already-discounted items
Exclude your sale collection from the discount, and turn off combination with product discounts so automatic sales and codes do not stack.
Country restriction
A launch code for one market spreads to other countries. Add a validation rule that blocks the code when the shipping country is outside the target market, with a message naming the eligible country.
Pitfalls and edge cases
- Blocking is heavier than not applying. A rejected code is a small annoyance, a blocked checkout is a bigger one. Use validation only when native settings cannot do the job.
- Vague error messages. "Checkout not allowed" generates support tickets. Name the code and the fix.
- Guest checkout. Tag- and segment-based rules depend on knowing the customer. Decide how guest customers should be treated.
- Codes from links. Codes can be applied automatically through checkout links. See our guide to Shopify checkout links and make sure your rules still apply.
How to do it with Blockly Checkout Customizer
Blockly Checkout Customizer, launching soon on the Shopify App Store, includes no-code checkout validation rules. To reject a code under certain conditions:
- Create a new validation rule.
- Add a condition for the discount code, such as "code is STAFF30".
- Add the conditions that make it invalid, such as "customer does not have tag staff" or "shipping country is not US".
- Write the error message customers will see.
- Save and test as both an eligible and an ineligible customer.
Rules run as Shopify Functions on Shopify's servers, so they work on any plan.
Takeaway
Most discount leakage can be fixed with native settings: customer segments, exclusions, combination limits, usage limits, and end dates. Use those first. For conditions Shopify does not cover natively, like country restrictions or tag rules on codes you cannot edit, add a checkout validation rule with a clear, actionable message. Audit your codes regularly, and your discounts will go to the customers they were meant for.
Related articles

Hide Express Checkout Buttons (Shop Pay, PayPal, Apple Pay) on Shopify Product and Cart Pages

Shopify Checkout Links: Pre-fill Products, Discounts and Customer Details

