> For the complete documentation index, see [llms.txt](https://help.dollarlabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/unified-discount/max-quantity.md).

# Max quantity

Max Quantity caps how many items get a Unified Discount, or skips the first N. Fixed and dynamic limits, which items it keeps, and worked examples.

**Max Quantity** caps how many **items** in the target get the discount. Use it for "50% off one pair", "$5 off every tee after the first" or "one beanie at half price for every two tees".

It counts items, not lines. For a cap on lines, see [Line limit](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/unified-discount/line-limit.md).

| Where                                                                  | Scope                                     |
| ---------------------------------------------------------------------- | ----------------------------------------- |
| **Max Quantity** flag on a **Discount** row                            | That row only. **Fixed** or **Dynamic**.  |
| **Maximum Quantity** block in the **Global Line Limit Strategy:** card | All product rows of the discount together |

Max Quantity works on **Product** rows only.

## Turn it on for a row

1. Click the gear button on the right of the value field. The **Flags** window opens.
2. Click **Max Quantity**, then **Close**.
3. A **Maximum Quantity** section appears at the bottom of the row, with a drop-down: **Fixed** or **Dynamic**.

To remove it, click the bin button on the right of **Maximum Quantity**.

## Fixed

Type a number in **Limit to: … items**.

| Number                     | Meaning                                                     |
| -------------------------- | ----------------------------------------------------------- |
| Positive, for example `1`  | Only this many items get the discount.                      |
| Negative, for example `-1` | Every targeted item gets the discount **except** this many. |
| Empty                      | No limit                                                    |

### Which items it keeps

When the target has items at different prices, the app sorts by the price of one item. The **Line Limit** strategy of the same row decides the order:

| Line Limit on the row                   | Positive number keeps    | Negative number skips    |
| --------------------------------------- | ------------------------ | ------------------------ |
| Not turned on, **First** or **Minimum** | the cheapest items       | the cheapest items       |
| **Maximum**                             | the most expensive items | the most expensive items |

To use **Maximum** without capping lines, turn on **Line Limit**, choose **Maximum** and leave **Limit to:** at `0`.

When only part of a line gets the discount, the cart and checkout can show that line split in two: the discounted items and the others.

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-57971c84dd23f344c579264c5006fd5a2fc24725%2Fmax-quantity-01-fixed-section.png?alt=media" alt="The Maximum Quantity section at the bottom of a product row: heading with a bin button, the text Limit the quantity of items this discount applies to, a drop-down set to Fixed, and a field Limit to: 1 items with the help text Leave blank for no limit. Use negative values to exclude N quantity of items from discount."><figcaption><p>Max Quantity, Fixed, 1 item.</p></figcaption></figure>

### Example: 50% off one pair of socks

{% hint style="success" %}
**Example store:** an outdoor apparel store in the US. Everyday Socks $14, Trekking Socks $18. Both carry the tag `fieldwork-socks`.
{% endhint %}

1. Open **Create Function** → **Unified Discount** → **General Discounts**.
2. Keep **Automatic discount**. **Title**: `Half price on one pair`. Tick **Use internal title**. In **Internal Title**, enter, for example, `Half-price socks`.
3. In **Discount #1 (PRODUCT)**, keep **Percentage** and type `50`. **Enter discount title**: `Half price on one pair`.
4. Click **Add Group**, name it `Socks`, and set **Product tag** · **is** · **contains one of** · `fieldwork-socks`.
5. In **Targets**, choose **Socks**.
6. Click the gear button, click **Max Quantity**, click **Close**. Keep **Fixed** and type `1`.
7. Set the start date to yesterday and click **Save**.

Cart: Everyday Socks × 1 ($14) and Trekking Socks × 2 ($18 each).

| Setting                                        | Item that gets 50% off     | Saving |
| ---------------------------------------------- | -------------------------- | ------ |
| Max Quantity `1` (no Line Limit)               | one pair of Everyday Socks | −$7.00 |
| Max Quantity `1` + Line Limit **Maximum**, `0` | one pair of Trekking Socks | −$9.00 |

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-edc551f3b1ef4cd65d0d45bfb67fa93d4cc44a21%2Fmax-quantity-02-cart-one-pair.png?alt=media" alt="Cart page: Everyday Socks × 1 with $14.00 struck through and $7.00 and the label Half price on one pair; Trekking Socks × 2 at $36.00 with no discount."><figcaption><p>Only the cheapest pair is half price.</p></figcaption></figure>

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-d82d92b80d9f1386fc8026f2d5b147b7e3c0c605%2Fmax-quantity-03-cart-one-pair-mobile.png?alt=media" alt="The same cart on a phone: Everyday Socks at $7.00 with the label Half price on one pair, Trekking Socks × 2 at $36.00."><figcaption><p>The same cart on a phone.</p></figcaption></figure>

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-862d254e6e45db8c9992196eb1d7fc8052d7e4b6%2Fmax-quantity-04-checkout-one-pair.png?alt=media" alt="Checkout order summary. Under the Everyday Socks, HALF PRICE ON ONE PAIR (−$7.00); the Trekking Socks have no label. TOTAL SAVINGS $7.00 under the total."><figcaption><p>Checkout: −$7.00 on the cheaper pair.</p></figcaption></figure>

### Example: $5 off every tee after the first

1. Create a **General Discounts** discount. **Title**: `$5 off extra tees`. **Internal Title**: for example, `Extra tee offer`.
2. In **Discount #1 (PRODUCT)**, choose **Fixed Amount** and type `5`.
3. Add a group `Tees` with **Product tag** · **is** · **contains one of** · `fieldwork-tees`.
4. **Rules**: **Tees** · **Quantity sum** · **is** · **greater than** · `1`. **Targets**: **Tees**.
5. Turn on **Max Quantity**, keep **Fixed** and type `-1`. Save.

Three Everyday Tees ($32 each): two of them get $5 off, so the saving is **−$10.00**. One tee alone gets nothing.

## Dynamic

**Dynamic** works out the cap from the cart. Pick **Dynamic** in the drop-down, then fill in:

| Field                                        | What to enter                                                                                        |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **Maximum Quantity** (**Limit to: … items**) | The highest the cap can go. Leave it empty for no ceiling.                                           |
| **Cart Group**                               | The group to count: **All (default)** or one of yours                                                |
| **Variable**                                 | **Line Count**, **Quantity Sum**, **Unique Product Count** or **Unique Variant Count** of that group |
| **Operator**                                 | **Add**, **Subtract**, **Divide (quotient)**, **Multiply**, **Modulo (remainder)** or **None**       |
| **Value**                                    | The number for the operator. Greyed out with **None**.                                               |

The app calculates: *Variable* *Operator* *Value*, then applies the ceiling. **Divide (quotient)** rounds down (5 ÷ 2 = 2). **Subtract** never goes below 1. **Modulo (remainder)** keeps the remainder (5 modulo 2 = 1). **None** uses the variable as it is.

{% hint style="warning" %}
**A result of 0 means no cap.** If the calculation gives 0 (for example 1 tee ÷ 2), every targeted item gets the discount. Add a rule so the row only runs when the result is at least 1. In the example below, that rule is **Tees** · **Quantity sum** · **greater than** · `1`.
{% endhint %}

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-d7f977c889ba47d5a0a62e6d45736d2906b4695c%2Fmax-quantity-05-dynamic-section.png?alt=media" alt="The Maximum Quantity section set to Dynamic: an empty Maximum Quantity field Limit to: items with the placeholder ∞, then four columns: Cart Group set to Tees, Variable set to Quantity Sum, Operator set to Divide (quotient), Value 2, and a sentence under them describing the calculation."><figcaption><p>Dynamic: one beanie for every two tees.</p></figcaption></figure>

### Example: one beanie at half price for every two tees

{% hint style="success" %}
**Example store:** Everyday Tee $32 (tag `fieldwork-tees`). Merino Beanie $30 in Moss and $24 in Charcoal (tag `fieldwork-beanies`).
{% endhint %}

1. Create a **General Discounts** discount. **Title**: `Beanie half price with tees`. **Internal Title**: for example, `Beanie with tees`.
2. In **Discount #1 (PRODUCT)**, keep **Percentage** and type `50`.
3. Add a group `Tees`: **Product tag** · **is** · **contains one of** · `fieldwork-tees`.
4. Add a group `Beanies`: **Product tag** · **is** · **contains one of** · `fieldwork-beanies`.
5. **Rules**: **Tees** · **Quantity sum** · **is** · **greater than** · `1`.
6. **Targets**: **Beanies**.
7. Turn on **Max Quantity** and choose **Dynamic**. Leave **Maximum Quantity** empty. Set **Cart Group** **Tees**, **Variable** **Quantity Sum**, **Operator** **Divide (quotient)**, **Value** `2`. Save.

Cart: Everyday Tee × 5, Merino Beanie Moss × 2 ($30 each), Merino Beanie Charcoal × 1 ($24).

* Cap: 5 tees ÷ 2 = 2 beanies (rounded down).
* The cheapest 2 beanies get 50% off: Charcoal (−$12.00) and one Moss (−$15.00).
* Saving: **−$27.00**. The second Moss beanie stays at $30.

With 7 tees the cap is 3, so all three beanies get 50% off.

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-a39998bc6f807791a29e4a00258db5d214b765d3%2Fmax-quantity-06-cart-dynamic.png?alt=media" alt="Cart page: Everyday Tee × 5; Merino Beanie Charcoal at $12.00 with its compare-at price $30.00 struck through; the Moss beanies split into two lines, one Moss at $30.00 with no discount and one Moss at $15.00 with $30.00 struck through. The discounted beanies carry the label Beanie half price with tees. Saving $27.00."><figcaption><p>Five tees unlock two half-price beanies. The cart splits the Moss beanies into two lines.</p></figcaption></figure>

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-7f961ec9567c4d61a6635a3c2aa7b6ed7c1a4dfd%2Fmax-quantity-07-cart-dynamic-mobile.png?alt=media" alt="The same cart on a phone, with the beanie discounts of $12.00 and $15.00 labelled Beanie half price with tees."><figcaption><p>The same cart on a phone.</p></figcaption></figure>

<figure><img src="https://2844543096-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcVBfwy7Yj4tU8TsxkHEr%2Fuploads%2Fgit-blob-6b28a36c89269b533c049884f228b15b80097de2%2Fmax-quantity-08-checkout-dynamic.png?alt=media" alt="Checkout order summary: the Merino Beanie Moss beanies on two lines, one at $30.00 and one at $15.00 with BEANIE HALF PRICE WITH TEES (−$15.00) under it; the Charcoal beanie with BEANIE HALF PRICE WITH TEES (−$12.00). TOTAL SAVINGS $27.00 under the total."><figcaption><p>Checkout: −$27.00, with the Moss line split in two.</p></figcaption></figure>

## Global maximum quantity

The **Global Line Limit Strategy:** card has a **Maximum Quantity** block with one field, **Limit to: … items**. It caps the items discounted by **all** product rows together.

* A positive number caps the total. A negative number skips that many items.
* It takes items off the lines with the **largest quantity** first, not by price.
* Empty means no limit. With **Max Discount Amount**, use the row's own **Max Quantity** and leave the global quantity limit unset.

## Limits

* **Product** rows only.
* On rows with **Specific Price**, Max Quantity takes items off the lines with the fewest items first, whatever their price.
* For **Variant Metafield Price**, control eligibility with cart groups and rules instead of **Max Quantity**.
* Shopify applies one saving per item from one discount. See [Function limitations by Shopify](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/function-limitations-by-shopify.md).

## FAQ

**Which pair gets the discount when the shopper buys different socks?** By default the cheapest. To discount the most expensive, also turn on **Line Limit**, choose **Maximum** and leave the limit at `0`.

**How do I make "every item except the first" work?** Use a negative number: `-1` skips one item. Add a rule that needs at least two items, so a single item doesn't trigger the row.

**My "1 free for every 2" discount gave everything free when the cart had only one item. Why?** The calculation gave 0, and 0 means no cap. Add a rule such as **Quantity sum** · **greater than** · `1` on the counted group.

## Related

* [Line limit](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/unified-discount/line-limit.md)
* [Max amount](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/unified-discount/max-amount.md)
* [Cart groups, rules and targets](https://help.dollarlabs.io/dollarlabs-ultimate-discounts/unified-discount/cart-groups-rules-and-targets.md)
