Skip to content
AgentReady
By Dylan HuntMarch 18th, 2026Updated November 12th, 2026Checkout and FunctionsShopifyCheckout blocksFunctions

Gift With Purchase on Shopify: Checkout Blocks, Functions, or No App at All?

Written by the Caffeine and Commerce team. For build work, see caffeinecommerce.com.

Gift with purchase looks like one feature, but on Shopify it's really two jobs: get the gift into the cart, and make it free. Every approach you'll read about handles those two jobs differently, and most disappointment with gift offers comes from assuming a tool does both when it only does one.

Here are the three real options, with what each one actually does.

Option 1: the built-in Buy X Get Y discount

Every Shopify plan includes Buy X Get Y discounts, as a discount code or an automatic discount. Buy the qualifying product, get the gift product free or discounted. No app, no code, live in five minutes.

The catch is in Shopify's own documentation: customers must add all items to their cart manually, and the free or discounted item is never automatically added. Your customer has to know the gift exists, find it, and add it themselves. For a self-serve "add your free tote at checkout" promo with good marketing around it, that's workable. For a surprise-and-delight gift that just appears, it isn't.

Start here anyway. If conversion on the offer matters more than polish, this is free and reliable.

Option 2: Checkout Blocks, with eyes open

Checkout Blocks is Shopify's free checkout customization app, and we covered the full feature map in our Checkout Blocks 101 post. For gift offers specifically, two facts matter:

  1. Its discount features are Shopify Plus only, like almost everything in the app beyond Thank you and Order status page content.
  2. Those discounts are order and shipping discounts, not product discounts. You can build a conditional rule like "when the cart contains the gift and subtotal is over $100, take $25 off the order." The math works out free, but the gift line still shows its normal price, and nothing adds the gift to the cart for you.

That's a legitimate setup for some offers, especially when you're already on Plus and already using the app. But if you want the gift line to read $0.00 with a "Free gift" label, an order discount can't draw that.

Option 3: a discount function, the polished version

A discount function can zero out the gift line itself, with a label, recalculated on every cart change. Remove the qualifying product and the gift's price comes back. This is the supported replacement for the gift-with-purchase line item Scripts that stopped running when Shopify retired Scripts on June 30, 2026.

The function only does the "make it free" job. It runs on Shopify's Discount Function API with the cart.lines.discounts.generate.run target, and the logic is the same decision the old Script made:

  1. Read the qualifying lines and their cost from the function's input.
  2. If the condition is met and the gift is in the cart, return a product discount that takes 100% off one unit of the gift line, with a message like "Free gift".
  3. If not, return nothing, so the gift is charged at full price.

A short sketch, with the gift variant and threshold hard-coded for readability:

const GIFT_VARIANT_ID = "gid://shopify/ProductVariant/1234567890";
const THRESHOLD = 100;

export function cartLinesDiscountsGenerateRun(input) {
  if (!input.discount.discountClasses.includes("PRODUCT")) {
    return { operations: [] };
  }
  const lines = input.cart.lines;
  const giftLine = lines.find((line) => line.merchandise.id === GIFT_VARIANT_ID);
  const qualifying = lines
    .filter((line) => line !== giftLine)
    .reduce((sum, line) => sum + parseFloat(line.cost.subtotalAmount.amount), 0);
  if (!giftLine || qualifying < THRESHOLD) {
    return { operations: [] };
  }
  return {
    operations: [
      {
        productDiscountsAdd: {
          selectionStrategy: "FIRST",
          candidates: [
            {
              targets: [{ cartLine: { id: giftLine.id, quantity: 1 } }],
              value: { percentage: { value: "100.0" } },
              message: "Free gift",
            },
          ],
        },
      },
    ],
  };
}

Its input query requests discount { discountClasses } and, for each cart line, the id, cost { subtotalAmount { amount } } and the variant id through a ... on ProductVariant fragment under merchandise. The threshold excludes the gift line, so the gift cannot help a cart qualify for itself. In a real build, keep the gift variant and threshold in the discount's metafield configuration so the merchant can change them without a deploy.

You deploy the function with the Shopify CLI, then create an automatic discount in the admin that points at it. Until that discount exists, the function does nothing.

Getting the gift into the cart is still separate work, done in your theme or with a gift-with-purchase app, and the two halves have to agree on the rules. If the cart-add trigger and the function's condition drift apart, a customer gets the gift in the cart without it being free, or free without qualifying. Functions also live inside apps, so the practical paths are a public App Store app that does this, which works on any plan, or a custom build, which Shopify limits to Plus stores when the app is custom to your store. What Shopify Functions can do covers that rule in more detail.

Picking between them

You wantUse
A working offer today, any plan, customer adds the giftBuy X Get Y discount
Conditional money-off when the gift is in the cart, on PlusCheckout Blocks order discount
Gift line shows $0.00, auto-added, edge cases handledDiscount function build

Whichever route you take, test the ugly cases: a cart that just qualifies and one that just misses the threshold, the customer removing the qualifying item after the gift lands, two gifts in the cart when the offer should free one, and a logged-out customer.

If your offer has outgrown the built-in discount and you want it built properly, that's work we do. The 25-idea Functions Playbook includes the gift pattern and the constraints around it, free.

Quick answers

Frequently asked questions

Can Shopify add a free gift to the cart automatically?
Not with built-in discounts. Shopify's docs are explicit that the free or discounted item in a Buy X Get Y offer is never automatically added to the cart. Auto-adding the gift takes theme code or an app, paired with a discount that makes it free.
Does Checkout Blocks support gift with purchase?
Partially. On Shopify Plus it can run custom order and shipping discounts with conditional rules, so you can take the gift's value off the order total. It doesn't create product discounts, so it can't show the gift line itself as free. For that you need a discount function.
Do I need Shopify Plus for a gift with purchase offer?
No. The built-in Buy X Get Y discount works on every plan. Plus only enters the picture if you want Checkout Blocks discounts or a custom app with a discount function built for your store.
What replaced gift-with-purchase Scripts?
Discount functions. Shopify retired Scripts on June 30, 2026, so line item Scripts no longer run. A discount function can take 100% off the gift line, but it cannot add the gift to the cart; your theme or an app does that part.

Comments

Every comment here comes from a verified email. Write yours, confirm from your inbox, and it's live.

Loading comments…

Leave a comment

ShareXLinkedInFacebook

Written by Dylan Hunt, Founder, AgentReady. AgentReady measures what AI says about Shopify stores and helps teams improve the answer. See plans.