Buy X get Y and free gifts in Shopify: how to build them with a discount Function

Updated · SMART Functions Creator (E-TRADE PARTNER)

In Shopify Functions, a free gift is a Product discount at 100 percent on a gift Line group, gated by a quantity condition on the qualifying Line group. SMART Functions Creator ships BOGO and Buy X get Y templates that set this up, including how many gift units are discounted and which units stay at full price. Two platform facts shape every design: the gift has to be in the cart already (a Function cannot add it), and repeating offers need explicit, bounded tiers.

5.0 · SMART Functions Creator builds this as a Shopify Function, free on live stores, no code.

Install free
On this page
  1. The building blocks
  2. Buy 2 get 1 free, same range
  3. Buy 2 get 1, buy 5 get 2, across two collections
  4. Discount one product only when another is present
  5. Every unit except one
  6. Bundle builders: complete the set, get 15% off
  7. Cumulative gift tiers and stacking
  8. Testing checklist
  9. Frequently asked questions

"Buy two, get one free" sounds like one rule. In practice it is four decisions: which items qualify, which items can be the gift, how many gift units are free at each quantity, and what happens when the customer adds more than the offer covers. This guide walks through each with the setups merchants actually asked for.

The building blocks

  • Qualifying Line group: the products that have to be in the cart. A collection, specific products or variants, a tag, a vendor, or a line item property.
  • Gift Line group: the products that can be discounted. Often the same group (buy 2 get 1 of the same range) or a different one (buy from collection A, get from collection B).
  • Condition: a quantity condition on the qualifying group, for example quantity is at least 2.
  • Action: Product discount, 100 percent, targeting the gift group, applied to the first N units, ordered by cart order, highest price, or lowest price.
  • Label: the wording the customer sees at checkout comes from the action label, not from the gift product's title.

Gifts are not added automatically

A Function can discount an eligible item to free, but it cannot put it in the cart. The customer, your theme, or another storefront feature has to add the gift product first. If you need auto-add, that is a storefront job, not a Function.

Buy 2 get 1 free, same range

  1. Create a Line group for the range (a collection works well).
  2. Start from the BOGO or Buy X get Y template.
  3. Condition: quantity in the Line group is at least 3 (two paid plus one free are all in the same group).
  4. Action: Product discount 100 percent on the same Line group, apply to the first 1 unit, ordered by lowest price so the cheapest unit is the free one.
  5. Set the label, activate, and test with 3, 4, and 6 units.

With 4 units in the cart the rule still frees exactly one, because the count of discounted units is fixed in the rule. To free two units at six, add a second rule or tier with a quantity condition of at least 6 and apply-to-first 2, and make the two conditions exclusive (3 to 5, then 6 and above) so they do not both fire.

Buy 2 get 1, buy 5 get 2, across two collections

A merchant asked for "two bought from collection A gives one gift from collection B, five bought gives two gifts, usable once". Build it as two bounded rules:

RuleCondition on collection A quantityAction on collection B group
Tier 1between 2 and 4100% off, apply to first 1 unit, lowest price first
Tier 25 or more100% off, apply to first 2 units, lowest price first

The ranges are exclusive so a cart of five does not get three free. "Usable once" is a usage limit on the discount itself when it is a code; automatic discounts cannot be limited to a customer's first use. If the merchant's test showed four gifts on five items, the two rules overlapped or the gift group was also part of the qualifying group; separating the groups fixes it.

Discount one product only when another is present

Put product A in the gift Line group and product B in the qualifying group, with a quantity condition of at least 1 on B. The offer can be automatic or attached to a code, and the same rule can be duplicated for other product pairs by swapping the Line groups.

Every unit except one

"Take 4.00 off every unit of this product except exactly one, and keep the most expensive unit at full price" is a fixed-amount Product discount rather than a gift. Apply-to-first with lowest price ordering discounts the cheapest units first, and the number of discounted units is set in the rule. Because the count cannot be "quantity minus one" dynamically, build one rule per quantity band (2, 3, 4, 5 units) with exclusive quantity conditions, up to the largest quantity you realistically sell. Repeating offers need finite tiers; this is a Shopify limit, not an app one.

Bundle builders: complete the set, get 15% off

For a four-step bundle where the customer picks one item from each of four collections, create four Line groups and a Product or Order discount with four conditions, each requiring quantity of at least 1 in its group. The discount applies only when all four are satisfied. To approximate a fixed combined bundle price instead of a percentage, use an Order discount of fixed amount limited to those Line groups; extra units of the same products will also be folded into the target while the rule matches.

Cumulative gift tiers and stacking

  • Separate Product discount rules with overlapping thresholds both apply, so a lower-tier gift stays free at the higher tier unless you make the conditions exclusive.
  • A Volume discount picks only the single highest tier, so it is not the right tool for "keep the first gift and add a second".
  • Gift plus free shipping works when the product discount and the shipping discount both allow combining with each other's class. See combining discounts.
  • Two product discounts never apply to the same unit. If a gift item is also covered by a sale discount, decide which one wins by excluding it from the other rule's Line group.

Start from the BXGY template and adjust

SMART Functions Creator is free on live stores and rated 5.0 stars across 110+ Shopify App Store reviews.

Install free

5.0 stars · 110+ reviews

Testing checklist

  1. Add the gift product manually; nothing will be free until it is in the cart.
  2. Test one unit below the threshold, at the threshold, and well above it.
  3. Confirm the free unit is the one you intended (lowest or highest price ordering).
  4. Check the checkout, not only the cart page. The theme controls cart display; the checkout shows the discount as calculated.
  5. If a subscription product is in the range, decide whether the gift should apply to subscription lines; Product discounts can be limited to one-time purchases.

Frequently asked questions

Can Functions Creator add the free gift to the cart automatically?

No. A Function discounts an eligible gift to free but cannot add it. The customer or a storefront feature has to add the gift product.

How do I stop a buy 2 get 1 offer from repeating?

The number of discounted units is fixed in the rule, so it does not repeat by itself. To cover higher quantities, add bounded tiers with exclusive quantity conditions.

Can I limit a gift offer to once per customer?

Only as a discount code with a one-use-per-customer limit. Automatic discounts cannot be restricted to first use.

Can the gift come from a different collection than the qualifying items?

Yes. Use two Line groups: a quantity condition on the qualifying group and a 100 percent Product discount on the gift group.

What text does the customer see for the free gift?

The discount action's label. Set it to something like "Free gift with 2 or more"; the gift product's title is not used.

Related articles