Back to Blog

By Dylan Hunt

June 1st, 2026

shopifyfunctionsguides

Free Gift With Purchase on Shopify Using Functions (Not Scripts)

Free Gift With Purchase on Shopify Using Functions (Not Scripts)

Free gift with purchase is one of the most popular promotions, and for years the way to build it on Shopify was a line item Script. Those Scripts stop working on June 30, 2026, so if you run a gift-with-purchase offer, it needs to move to Shopify Functions before then. Here is how the modern version works.

This recipe replaces the approach in our older BFCM free-gift Scripts post. For the full migration picture, see the Scripts to Functions guide.

The two parts of a gift offer

A free gift promotion is really two jobs, and it helps to separate them:

  1. Get the gift product into the cart when the offer conditions are met (for example, the cart total is over a threshold, or a qualifying product is present).
  2. Make the gift free so the customer is not charged for it.

Scripts blurred these together with a price change. Functions are cleaner: a discount function handles making the gift free, while adding the gift to the cart is handled separately, by your theme, an app, or Shopify's bundling and cart features.

Building it with a discount function

A product discount function is the right tool for the "make it free" half. It reads the cart, checks your conditions, finds the gift line item, and returns a 100% discount on that item with a clear message like "Free gift."

The logic is the same decision your Script made:

  • Read the cart total or the qualifying items from the function's input.
  • If the conditions are met and the gift is in the cart, return a product discount that zeroes out the gift's price.
  • If not, return nothing.

You deploy the function with the Shopify CLI, then create an automatic discount in the admin that points at it so it runs at checkout.

Getting the gift into the cart

This is the part to plan, because it is not the discount function's job:

  • Theme or app: add the gift to the cart with a small storefront script or a gift-with-purchase app when the threshold is reached.
  • Make the rules match. The "add to cart" trigger and the discount function's conditions must agree, or a customer could get the gift in the cart without it being free, or the reverse.

Test these cases

  • Cart that just qualifies, and cart that just misses the threshold.
  • Customer removing the qualifying product after the gift is added.
  • More than one gift in the cart, if your offer should only free one.
  • Logged-out customers.

Want it built and tested before the deadline

Gift offers have a lot of edge cases, and a broken one either gives away product or charges for the gift. We build gift-with-purchase on Shopify with Functions and test every edge case. Send us your current offer and we will rebuild it before June 30, 2026.

ShareXLinkedInFacebook

Written by Dylan Hunt, Founder, Caffeine and Commerce. We build Shopify stores that rank and that AI agents can read. Have a project? Get in touch.