Discount function · Plan: Basic
How do I make the cheapest of three items free, or the most expensive one half price?
Use a product discount rule with a quantity condition and set the target selection to cheapest matching or most expensive matching with a target quantity. Checkout picks the line to discount from the items that match your conditions. Works on every Shopify plan.
- Function typeDiscount
- Plan neededBasic
- Shopify PlusNot required
- Updated
What the shopper sees
With three eligible shirts in the cart, the cheapest line shows 100% off one unit. With two, nothing happens. With six, two are free if you set the target to scale, or one if you cap it.
How the rule is built
- Add a product discount rule.
- Condition: quantity sum across the eligible products ≥ 3 (use the collection or tag aggregate so different shirts count together).
- Target selection: cheapest matching, target quantity 1.
- Value: 100% for “free”, 50% for “half price”.
For “most expensive half price” switch the target selection to most expensive matching.
| Offer | Condition | Target | Value |
|---|---|---|---|
| Buy 3, cheapest free | Collection quantity sum ≥ 3 | Cheapest matching, qty 1 | 100% |
| Buy 2, dearest half price | Collection quantity sum ≥ 2 | Most expensive matching, qty 1 | 50% |
| Buy 2 get 1 free, repeating | Collection quantity sum ≥ 3 | Cheapest matching, qty = floor(sum / 3) | 100% |
The repeating version needs the target quantity computed from the cart, which uses a variable and is an Advanced plan feature. The one-time versions are Basic.
Variations
- Y from a different set than X. Condition on one collection (the X items), target lines in another collection (the Y items), so “buy a lamp, get 50% off a bulb”.
- Cap how many are discounted. Target quantity is a hard cap, so “cheapest free, max 1 per order” is the default behavior.
Limits to know
- “Cheapest” and “most expensive” compare unit prices of the lines that match the rule’s line conditions, not the whole cart.
- Native Shopify also offers a Buy X Get Y discount. The Function version is for the cases native cannot express: metafield or tag conditions, cheapest-across-collections, and combining with other rules in one function.