Back to Blog

By Dylan Hunt

May 22nd, 2026

shopifyfunctionsguides

Replacing Shopify discount Scripts with discount Functions

Replacing Shopify discount Scripts with discount Functions

If you give automatic discounts at checkout with a Shopify Script, that code stops running when Scripts retires on June 30, 2026. The good news: discounts are the most straightforward thing to move to Shopify Functions, and the new version is faster and works on more plans.

This is the focused version for discounts. For the full picture across discounts, shipping, and payments, read the Scripts to Functions migration guide.

What you have today

A line item Script in the Script Editor that reads the cart and applies a discount. Common patterns:

All of these are the same shape: look at the cart and customer, decide a discount, return it.

What it becomes

A discount function, an app extension you build with the Shopify CLI in JavaScript or Rust. It declares the cart and customer fields it needs in a GraphQL input query, runs a run function, and returns discount operations. You attach it to an automatic discount (or a discount code) in the admin, and it fires at checkout.

The logic maps almost one to one. A Script that did this:

# Old: line item Script
if Input.cart.subtotal_price >= Money.new(cents: 10000)
  Input.cart.line_items.each do |item|
    item.change_line_price(item.line_price * 0.9, message: "10% off orders over $100")
  end
end

becomes a function whose run reads the cart subtotal from its input and returns a 10% order discount with the same message. The decision (subtotal at or above $100) is identical, you are just returning an operation instead of mutating the cart in place.

The migration in five steps

  1. Create a custom app if you do not already have one. Functions ship as extensions of an app.
  2. Generate a discount function with the Shopify CLI and choose the discount API.
  3. Request only the inputs you need (cart cost, customer, line item attributes) in the function's input query, this is what keeps it fast.
  4. Port your rule into run. Return a product discount or order discount with the same threshold and message your Script used.
  5. Deploy, then create an automatic discount in the admin that points at the function. Test in a real checkout, then delete the old Script.

Watch for these

  • A discount function does nothing until an automatic discount (or code) in the admin is attached to it. The function alone is not enough.
  • Free gifts usually combine a discount function (to make the gift free) with how the item gets added to the cart, plan that flow, do not assume the Script's change_line_price trick carries over unchanged.
  • Re-test logged-out customers and mixed carts. Inputs that are not in your query are invisible to the function.

Need it done before the deadline

We migrate discount Scripts to Functions every week. Send us your Script Editor list and we will rebuild each one, tested and live, well before June 30, 2026.

Make your store agent-ready

Get found and recommended by AI shopping assistants.

AgentReady adds Schema.org structured data, an llms.txt directory, and an AI-readability audit to your Shopify store, so ChatGPT, Perplexity, and Google can understand and recommend your products. Free for stores under 500 products.

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.