Discount function · Plan: Advanced
How do I sell any 5 items from a collection for 60, with any extra items at regular price?
Use a discount function with variables and line groups: count eligible units, compute how many full packs of five fit, and apply a fixed price to that many units. Leftover units keep their price. This needs the Advanced plan and no Shopify Plus.
- Function typeDiscount
- Plan neededAdvanced
- Shopify PlusNot required
- Updated
What the shopper sees
They put seven socks from the collection in the cart. Checkout prices five of them at 60 total and the remaining two at regular price. Add three more and two full packs are priced at 120. The pack can mix any products from the collection, in any sizes.
How the rule is built
This is the pattern that native discounts and the Basic plan cannot do, because the number of packs is computed from the cart.
- Define a line group: all lines in the collection (or with a tag). The group gives you the total eligible units and lets later steps target units across lines.
- Define a variable
packs = floor(groupQuantity / 5). - Add a product discount rule with the condition
packs ≥ 1, target the group’s cheapest units, target quantitypacks × 5, value type fixed price with amountpacks × 60.
| Cart | packs | Units priced | Price |
|---|---|---|---|
| 4 units | 0 | 0 | regular |
| 7 units | 1 | 5 | 60 + 2 regular |
| 10 units | 2 | 10 | 120 |
Targeting the cheapest units means the shopper always pays regular price on the dearer leftovers, which is the usual retail convention. Switch to most expensive matching if you prefer the pack to absorb the dearer units.
Variations
- Multiple pack sizes. Add a second variable and rule for “any 10 for 110”; order the rules so the larger pack is evaluated first.
- Packs per product instead of across the collection. Use the per-product quantity sum instead of a cross-line group.
- Pack price from a metafield. Store the pack size and price on the collection’s products or in a metaobject and read them in the variable, so merchandising can change the offer without touching rules.
Limits to know
- Variables and line groups are an Advanced plan feature.
- Up to ten rules per function.
- Test it in the test panel with odd quantities, such as 4, 7, and 11, before activating.