Shopify Scripts retired on 30 June 2026. If a promotion still depends on an old Script, check what customers actually receive at checkout. The replacement is an app using Shopify Functions, with each rule mapped and tested rather than copied blindly.
This guide covers custom discounts on Shopify Plus: the current Discount Function API, common promotion patterns, development workflow and checks before launch. Your team owns the rules and approves the release; AI can help with implementation, but it does not replace review or checkout testing.
From Scripts to Functions: what actually changed
Shopify Scripts used Ruby to customise checkout behaviour. Shopify has retired Scripts and the Script Editor; old Scripts no longer run.
Shopify Functions are a different model. You write logic in Rust or JavaScript, compile to WebAssembly, deploy via Shopify CLI, version with your app. The runtime is Shopify-hosted but the code is yours, in your repo, with proper testing and review workflow.
The job now is to check that every promotion, delivery rule and payment rule has a supported replacement. Start with the customer outcome, then choose the Function API that can deliver it.
One Discount Function API, three discount classes
The unified Discount Function API covers product, order and shipping savings. The older separate APIs are deprecated. One discount can combine classes; the examples below describe the promotion rules, not three separate APIs to scaffold.
Product discounts
Applies discounts to specific cart lines. Use case: "buy this product and get 20% off," or "this collection is 15% off for VIP members," or "discount applies only to specific variants."
Use product discount candidates for the qualifying cart lines.
Granular. You target individual cart lines, individual variants, individual quantities within a line.
Order discounts
Applies savings to the order subtotal. For example: "10% off orders over $200" or "$15 off when the cart contains items from two categories." A "free item over $300" offer needs product-level eligibility and a way to add the gift to the cart.
Use order discount candidates when the saving depends on the qualifying subtotal.
Best for any logic that depends on cart composition rather than individual lines.
Shipping discounts
Reduces eligible delivery costs. For example: "free shipping over $75," "$5 off Express shipping for members," or "free Express shipping during a promo window."
Use the delivery-options target for shipping discount candidates.
Discounts reduce the price of an available option. Renaming, hiding or reordering options is a separate delivery customisation requirement.
The development workflow
Scaffolding
Use Shopify CLI to generate the current discount extension. Keep its generated schema and API version together; do not copy a payload from a deprecated API into a new extension.
The input query is the most important part of the function. It defines what cart and customer data Shopify will pass to your function. Get this right early, because changing it later means redeploying.
Writing the function
Write and review the promotion rule against the generated input and output types. Choose the implementation language your team can maintain and test within Shopify's resource limits.
Profile realistic carts, including the largest orders and combinations your store supports. A small test cart is not enough evidence that a promotion is safe to launch.
Deployment and configuration
Functions deploy via shopify app deploy as part of an app. After deploy, you create discount records in the Shopify admin that reference the function. The merchant-facing config lives in metafields on the discount record.
This is the bit that catches new teams: a Function does not become "active" just by deploying. You have to create at least one Discount record in the admin that uses the Function. That Discount record can be automatic (always on for matching carts) or code-based (shopper enters a code).
Common patterns
Tiered discounts
"Spend $100, get 10% off. Spend $200, get 15% off. Spend $300, get 20% off."
Read the qualifying subtotal and return the matching order saving. The retained example below shows the original tier calculation and legacy output shape; it is not a drop-in implementation for the unified API. Use the current Discount Function reference when wiring the same thresholds into a new extension.
function run(input) {
const subtotal = parseFloat(input.cart.cost.subtotalAmount.amount);
let percentage = 0;
if (subtotal >= 300) percentage = 20;
else if (subtotal >= 200) percentage = 15;
else if (subtotal >= 100) percentage = 10;
else return { discounts: [] };
return {
discounts: [{
message: percentage + "% off your order",
targets: [{ orderSubtotal: { excludedVariantIds: [] } }],
value: { percentage: { value: percentage } }
}]
};
}BOGO (buy one get one)
"Buy two of product X, get the cheapest one free."
Count qualifying units, identify the lowest-priced eligible unit and target a 100% product saving. Check quantities and combinations so the same item is not rewarded twice.
Test large carts as well as the simple offer. Counting and sorting should stay bounded, and a failed discount must be visible in monitoring.
Member pricing
"Customer tags include 'vip' get 15% off site-wide."
Choose an order saving for the qualifying subtotal or product savings for selected lines. Request the relevant customer fields and define a safe fallback when no customer is available.
Do not assume a customer object is present in every checkout. Test guest and recognised-customer paths separately before relying on tags for eligibility.
Dynamic bundle discount
"Add three items from this collection, get 25% off all three."
A Discount Function can apply the saving, while Cart Transform handles supported bundle presentation and line operations. Check the Cart Transform reference for the exact operation your bundle needs.
For bundle operations, use the Cart Transform reference linked above. Cart-line transformations run before line-discount calculation, so test the final savings against the transformed cart.
Segment-specific offers
"First-time customers get 20% off their first order."
Request the available customer order count in the input schema and define exactly what qualifies as a first order. Do not guess whether the current checkout is included; test new, returning and guest customers.
Performance characteristics
Use the current Function resource limits for the API version you deploy. The previous fixed-time and payload figures in this guide were not a reliable implementation reference.
- Check instruction, memory, input and output limits against representative carts.
- The run target uses its input. Approved fetch targets can supply external data where that API and store are eligible.
- Review activation limits by Function type; checkout UI extensions are a separate surface.
Shopify permits up to 25 active discount functions per store. That is a discount-specific limit, not a shared allowance for every Function and checkout extension.
Limits and gotchas
Order of execution
Discount Functions run after Cart Transform Functions, in the order: Cart Transform → Discount Function → Shopify discount engine. Your function output goes into Shopify's discount pipeline, which then applies eligibility rules, combinability, and stacking.
Discount combinability
Configure combinations on the discount records and test the actual winning savings. Shopify supports eligible product, order and shipping combinations; an order discount is not automatically incompatible with every other order discount. See Shopify's combination rules.
Manual discount codes vs automatic
A Function can be triggered by an automatic discount (always on) or a code (shopper enters a code). The Function code is identical; the trigger lives on the Discount record in the admin. Same function, different activation modes.
Discount record limits
Shopify has separate limits on the number of Automatic Discounts and Discount Codes per shop. Functions do not bypass those limits. If you are running dozens of campaigns, plan the discount record budget.
Testing on a dev store
Functions deploy via the CLI and install via apps. On a dev store, you can test the full flow end to end. Always test on a dev store before pushing the app to production.
Migration from Shopify Scripts
Most Scripts can be ported to Functions. The mapping is roughly:
- Line-item savings map to the Discount Function API.
- Shipping savings map to discounts; changing available delivery options uses Delivery Customization.
- Payment-method rules map to Payment Customization, subject to its supported operations.
Patterns to watch:
- Supply required data through supported inputs. Check eligibility before planning a network-backed rule.
- Map cart-line requirements to supported Cart Transform operations, rather than assuming it can add or remove any item.
- Rework complicated conditions into explicit rules with expected results for each test cart.
If an old Script still appears in the brief, treat it as a specification to review, not a working fallback. Check live behaviour before planning replacement work.
Where to start
One: inventory the old Scripts and the current apps. Record what each rule should do and whether it works today. Retire rules the business no longer needs.
Two: start with a simple tiered order saving in the unified API. Confirm its expected result before layering on bundles or more campaigns.
Three: build the input GraphQL query first. Spend an hour getting it right. The query defines the data shape your function logic operates on, and rewriting it later is painful.
Four: test exhaustively on a dev store before deploying to production. Discount logic that fires wrong on day one of a campaign can refund a lot of money to a lot of customers.
If you want help scoping a Scripts-to-Functions migration or building custom discount logic, book a technical review. We will audit your current discount stack and tell you what to migrate, what to retire, and what to rebuild from scratch.
Are Shopify Scripts being deprecated?
Shopify Scripts and the Script Editor retired on 30 June 2026. Scripts no longer run. Check current checkout behaviour and replace required rules with an app using the appropriate Function API.
What is the difference between a Discount Function and a Cart Transform Function?
Discount Functions calculate savings. Cart Transform changes supported cart-line pricing and presentation, including bundle operations. It is not a general-purpose API for adding or removing any product. Map each requirement to its supported operation.
Can a Discount Function read customer data?
Yes, through the customer fields available in its input schema. A customer may be absent, so test guest and recognised-customer flows and define what happens when eligibility data is missing.
Rust or JavaScript for Discount Functions?
Choose a supported language the team can maintain, then profile representative carts against the current resource limits. Shopify recommends Rust for performance. Do not choose based on a supposed fixed execution-time allowance.
How many Functions can a Shopify Plus store run at once?
Limits depend on Function type. Discount Functions allow up to 25 active per store; that is not a shared limit covering every Function and checkout UI extension. Review each API used by the installed apps.
Can I trigger a Discount Function with a code?
Yes. Functions can be triggered by an automatic discount (always on for matching carts) or by a code (shopper enters the code at checkout). The function code is the same; the trigger is configured on the Discount record in the admin.
What happens if a Discount Function fails?
Shopify discards that run's output, does not apply its discount and lets checkout continue. Test failure paths and monitor them so customers are not silently missing an advertised saving.
How long does a Scripts-to-Functions migration take?
Depends on the complexity of your Scripts stack. A typical Plus brand with 5-10 Scripts ports in 4-8 weeks including testing. Brands with complex multi-Script logic can take 12-16 weeks.
Does AI recommend your brand?
We ask ChatGPT and Perplexity 10 real buying questions for your category and score you against your biggest competitor. Live, in about 2 minutes.
Free. Enter your store's website, e.g. yourstore.com
Flux is a Shopify Plus Agency for Advanced Engineering & AEO
- Scripts retired on 30 June 2026. Check that required promotions now work through supported apps and Functions.
- The unified Discount Function API handles product, order and shipping savings.
- Keep tiered offers, BOGO, member pricing and bundle examples tied to explicit eligibility rules.
- Use the current resource and activation limits for each API, not a generic time limit.
- Test guest customers, large carts, discount combinations and failure paths before launch.
- The retained code example illustrates legacy output; use the current reference for a new implementation.




