# Create a discount code with rules

One code customers enter at checkout that discounts different collections and products by different amounts, using a rule for each.

Most discount codes do one thing. **Discount Code** does several at once: a single code that carries its own set of rules, each giving a different discount to a different part of your catalogue.

One code can take 20% off body care and 30% off face care, and the customer only ever types `BLACKFRIDAY`.

This is the discount to reach for when a promotion is not uniform. A sitewide sale with a few richer categories, a spend threshold that unlocks a better rate, or different treatment for subscription and one-time purchases all fit in one code.

### Create one

In **Discounts**, create a discount and choose **Discount Code** from **Select discount method**, described there as _One code customers enter at checkout, with its own discount rules_.

![](https://cdn.sanity.io/images/qnhxgxnh/production/1f3d489d2be18964d46a762fe02032d804c2db5f-1386x1134.png?w=1600&fit=max&auto=format)

> **Note:** Do not confuse it with **Discount Code Generator**, directly above it. The Generator creates and sends codes automatically from a trigger, such as a birthday. This one is a single code you create and publish yourself.

1. **Name it and set the code**
   **Name** is for your reference only and is never shown to customers.

   Under **Discount code**, type the **Code** customers will enter, or click **Generate** for a random one. Capital letters do not matter at checkout.

2. **Add your first rule**
   Each rule is one discount applied to one set of products.

   - **Applies to**, then pick the collections or products the rule covers. Use **Select collections** or **Browse**, and **+ Add products** to name individual products as well.
   - **Discount type** and **Value**, for example `Percentage` and `20`.
   - **Purchase type**, either one-time or subscription.
   - **Minimum purchase requirements**, covered below.

   ![](https://cdn.sanity.io/images/qnhxgxnh/production/7fcfd19ebb41279e6d69affca0d9659868287299-1030x1150.png?w=1600&fit=max&auto=format)

3. **Add the rest**
   Add a rule for each part of the catalogue that needs a different discount. Rules are numbered **Rule 1**, **Rule 2** and so on, and each has its own **Delete rule**.

   There is no shared setting between rules. Each one carries its own targeting, discount, purchase type and minimum.

   ![](https://cdn.sanity.io/images/qnhxgxnh/production/5a33bf1b5a4cf1bc6d75fe7ca44b81f4e132d979-1002x1010.png?w=1600&fit=max&auto=format)

4. **Set the code-level settings**
   Below the rules, four cards apply to the code as a whole rather than to any single rule:

   - **Maximum discount uses**: limit the total number of uses, limit to one use per customer, or both.
   - **Customer Eligibility**: all customers, logged-in only, customers with or without a given tag, members, or non-members.
   - **Active Dates**: a start date and time, and optionally an end date and time.
   - **Combinations**: which other discounts this code can stack with, across product, order and shipping discounts.

   ![](https://cdn.sanity.io/images/qnhxgxnh/production/1fe8809a5732270dbe283eed525e9bc17b9a538e-1040x1376.png?w=1600&fit=max&auto=format)

### How the rules resolve

One principle covers everything the code does:

> **Note:** A rule applies only when its own conditions are met, meaning its minimum and its purchase type. Among the rules that do apply to a product, the **best single discount wins**.

Two consequences follow.

**A product in no rule gets no discount.** The code is not a sitewide percentage with exceptions. If you want everything covered, every product needs to fall inside a rule.

**Discounts never add together.** A product matching a 20% rule and a 30% rule pays 30%, not 50%. This is what makes layering safe: you can add a richer rule over the top of a broad one without having to carve anything out of the broad one.

That layering is the whole technique. A rule can cover the same collection as another rule, with a different minimum or a different purchase type, and the customer simply lands on whichever one they qualify for.

### Minimum purchase requirements

Each rule carries its own, so one rule can require a spend while another applies immediately.

| Option | What it checks |
| --- | --- |
| **No minimum requirements** | The rule always applies to its products |
| **Minimum purchase amount ($)** | The cart's total amount |
| **Minimum quantity of all products in cart** | The total quantity of all units in the cart |

Both minimums look at the **whole cart**, not at the products the rule targets. A $250 minimum on your face-care rule is met by $250 of anything, not $250 of face care.

### One-time and subscription purchases

**Purchase type** lets one code treat the two differently. Point two rules at the same collection, set one to one-time purchase and the other to subscription, and each gets its own discount.

A subscription receives the discount on its **first order only**, not on every renewal.

So a cart holding the same product twice, once as a one-off and once on subscription, shows two different savings from the same code.

### What the customer sees

The code is entered at checkout like any other. Each discounted line shows the code name against the saving on that line, for example `BLACKFRIDAY (-$28.80)`, with the original price struck through, and the cart shows a total saving across everything.

Because each line names the code, a customer can see at a glance that one code produced several different amounts, which heads off the "my discount only partly applied" question.

![](https://cdn.sanity.io/images/qnhxgxnh/production/14777ea4654ed6dd220489153f60d9ef8b693a69-772x834.png?w=1600&fit=max&auto=format)

### Some example combinations

Three promotions that are awkward to build any other way.

#### Different collections, different discounts

The straightforward case: one code, a richer rate on your higher-margin range.

- **Rule 1**: `Body` collection, Percentage `20`, one-time purchase, no minimum
- **Rule 2**: `Face` collection, Percentage `30`, one-time purchase, no minimum

A customer buying a Hair Serum at $96.00 and a Body Wash at $59.00 pays $67.20 and $47.20. The cart shows `BLACKFRIDAY (-$28.80)` on the serum and `BLACKFRIDAY (-$11.80)` on the wash, with a total saving of $40.60.

Anything outside both collections is charged at full price.

#### Spend more, save more

Two rules on the **same** collection, separated by a minimum, turn one code into a spend ladder.

- **Rule 1**: `Body` collection, Percentage `20`, no minimum
- **Rule 2**: `Body` collection, Percentage `30`, minimum purchase amount `$250`

Under $250 only the first rule qualifies, so the customer gets 20%. At $250 both qualify, and the better of the two wins, so the whole collection jumps to 30%.

You do not need to exclude anything from the first rule. It stays as the floor and the second rule overtakes it.

#### One-time and subscription priced differently

Use a better rate to push customers toward subscribing.

- **Rule 1**: `Body` collection, Percentage `20`, one-time purchase
- **Rule 2**: `Body` collection, Percentage `30`, subscription

A customer with the same Body Wash in their cart twice, once as a one-off and once on subscription, sees `BLACKFRIDAY (-$11.80)` on the one-off, taking $59.00 to $47.20, and `BLACKFRIDAY (-$15.93)` on the subscription line, taking $53.10 to $37.17. Total saving $27.73.

The subscription line is already discounted by its plan before the code applies, and the code's saving is on top of that for the first order.

### Related guides

- [Create a product discount](https://www.roadmap.so/docs/discounts-and-gwp/using-gwp-and-discounts/create-a-product-discount)
- [Create an order discount](https://www.roadmap.so/docs/discounts-and-gwp/using-gwp-and-discounts/create-an-order-discount)
- [Discount Code Generator](https://www.roadmap.so/docs/discounts-and-gwp/using-gwp-and-discounts/discount-code-generator)
- [Use tags for discount eligibility](https://www.roadmap.so/docs/discounts-and-gwp/using-gwp-and-discounts/use-tags-for-discount-eligibility)
- [Run multiple discounts & GWPs](https://www.roadmap.so/docs/discounts-and-gwp/using-gwp-and-discounts/run-multiple-discounts-and-gwps)
- [Discounts not applying correctly](https://www.roadmap.so/docs/discounts-and-gwp/troubleshooting/discounts-not-applying-correctly)
