Limit a discount to one item on Shopify — after Scripts.
A % discount that's supposed to hit exactly one eligible item — a cheapest item, a single welcome-gift SKU — will hit every matching item instead if you rebuild it with a native Shopify discount. This is one of the more common things an old Script did that has no native equivalent. Here's how a Discount Function does it correctly.
Why native discounts can't do this
Shopify's built-in automatic discounts and discount codes apply their percentage or amount to every line item that matches the entitled products, collections, or variants you set. There's no native setting that says "apply this to one unit, total, across the whole cart" — if three eligible items are in the cart, all three get discounted, not one.
That's fine for a sitewide sale. It's the wrong behavior for cases like:
- A "20% off your cheapest eligible item" promotion
- A single free or discounted gift item once a customer qualifies
- A loyalty perk that should apply once per order, not once per matching line
This was one of the more common patterns in old Shopify Scripts — a Ruby loop that found the first or cheapest matching line and applied the discount there, then explicitly stopped, leaving every other matching item untouched. Native discounts have no equivalent stop condition.
How a Discount Function limits it to one item
A Shopify Discount Function runs custom logic against the whole cart before the discount is applied, which is exactly the control a native discount doesn't give you. The pattern looks like this:
Find eligible lines
The Function checks every cart line against your conditions — specific products, a minimum quantity, a customer tag — and builds a list of lines that qualify.
Pick one
From the eligible list, the Function selects a single line — typically the cheapest, so the discount value is predictable and capped, though the exact selection rule is configurable.
Target only that line
The discount is applied to that one line only. Every other eligible line in the cart is left at full price, exactly like the old Script's "find one, stop" behavior.
✓ discount applied (cheapest)
If you still have the Ruby from the old Script that did this, Scriptly's AI importer can read it and map it to this exact pattern — see converting a Ruby Script to a Function. If you don't, it's one of the templates you can configure directly with no code.
Testing it: the 10-item cart
Before turning a one-item discount rule on, test it against a cart big enough to catch the edge cases a small cart would miss:
- Add at least 3–4 items that qualify for the discount, at different prices
- Add 5–6 items that don't qualify, so you can confirm they're untouched
- Confirm exactly one eligible line shows the discount, and it's the one your selection rule (usually cheapest) predicts
- Confirm every other eligible line — the ones that didn't get picked — stays at full price
- Re-run the same cart in a simulator or draft mode before switching the rule on live, so a checkout customer isn't the first person to see the result
Frequently asked questions
Can a Shopify discount code apply to just one item in the cart?
Not with a native automatic discount or discount code — those apply to every matching line item. Limiting a discount to a single item requires a Discount Function that finds all eligible lines, picks one, and targets only that line.
Which item gets picked if more than one qualifies?
Typically the cheapest eligible line, so the discount amount stays predictable — but the selection rule is configurable depending on how the Function is built.
Did my old Shopify Script do this the same way?
Likely yes — this was a common Script pattern: loop through cart lines, find the first or cheapest match, apply the discount, then stop. A Discount Function reproduces that same find-one-and-stop behavior.
How do I test that only one item is discounted?
Build a test cart with several eligible items and several non-eligible ones — at least 10 total — and confirm exactly one eligible line shows the discount while the rest stay at full price, ideally in a simulator before the rule goes live.
Is this different from a "buy one get one" discount?
Yes. A one-item discount reduces the price of a single eligible line regardless of what else is in the cart. A BOGO discount ties the discount to a purchase condition — buying a certain quantity — and is a separate rule template.
Build the one-item discount rule now.
Scriptly's free plan runs one active discount rule with the full simulator, no credit card required.