---
title: "Shopify Functions for Discounts: What Replaced Scripts"
description: "A Function computes the outcome you intended rather than hoping several discounts cooperate. That single property removes most of the failure modes merchants live with."
author: "Aashish Kaushik"
published: 2026-10-20T13:00:29.159Z
updated: 2026-10-20T13:00:29.163Z
url: https://blog.byteinfy.com/shopify-functions-discounts
---
# Shopify Functions for Discounts: What Replaced Scripts

## Key takeaways

- Functions run server-side at checkout, so a discount cannot be visible in the cart and absent at payment.
- They hold through accelerated checkouts, unlike anything implemented by manipulating the cart.
- Discount Functions are available beyond Plus, which is a meaningful widening compared with the old Scripts boundary.
- Build configuration into the Function from the start, or every future threshold change becomes a deployment.

Legacy Shopify Scripts stopped running on 30 June 2026. What replaced them is not a like-for-like substitute, and the difference is worth understanding before scoping any custom discount work.

Functions are compiled code running server-side at defined extension points. That architecture is what gives them the property merchants care about most: a discount computed by a Function cannot be visible in the cart and missing at checkout, because it is the same computation.

> **The one-line summary**
> 
> Native discounts for standard offers. Apps for standard offers plus storefront messaging. Functions when the outcome you want cannot be expressed by either.

## What a Function actually is

Code you write, compiled to WebAssembly, deployed through a Shopify app, and executed by Shopify at a specific point — when discounts are calculated, when delivery options are assembled, when payment methods are presented.

Practically, three properties matter:

**Server-side execution.** The result is computed by Shopify, not by JavaScript in a browser that may or may not run.

**Bounded and fast.** Functions run within clearly defined execution limits, which is why they are predictable in a way that Scripts never were.

**Deployed, not edited.** There is no admin text box to type into. The code lives in a repository and reaches production through an actual deployment.

That last one is the largest workflow change from Scripts, and the one to plan around.

## Why the cart-versus-checkout problem disappears

The failure merchants know best: a discount appears in the cart and vanishes at checkout, or a shopper using Shop Pay pays full price.

The cause is implementation. Some apps achieve pricing by manipulating the cart — adding line items, rewriting the cart through the storefront, routing through draft orders. Those approaches work in the normal flow and are bypassed when a shopper takes a path that skips the cart, which accelerated checkout buttons do.

A Function applies at the platform level. There is no separate cart computation to diverge from, and nothing for a wallet button to skip past.

This is the single strongest practical argument for Functions, and it is worth asking any vendor directly: is the discount applied through Functions, or by modifying the cart? The answer separates the category more reliably than any feature comparison, and a vendor who cannot answer it clearly has told you something useful.

## What Functions express well

## Where Functions earn their cost
| Requirement | Native | App | Function |
| --- | --- | --- | --- |
| Simple percentage or buy X get Y | Yes | — | Unnecessary |
| Automatic free gift in cart | No | Usually | Yes |
| Conditional on customer tag or history | No | Sometimes | Yes |
| Multi-rung tiered thresholds | Awkward | Usually | Yes |
| Combined outcome of overlapping offers | No | Rarely | Yes |
| Hiding or reordering payment methods | No | Sometimes | Yes |
| Hiding or renaming delivery rates | No | Sometimes | Yes |
| Storefront offer messaging | No | Yes | Needs theme work |

The row worth dwelling on is the combined outcome. Shopify's rules about combining same-type discounts mean two product discounts generally will not stack, and merchants spend a lot of effort trying to make several offers cooperate.

A Function sidesteps this entirely. Instead of hoping two discounts resolve correctly, you evaluate the cart once and emit the result you intended. There is no combination setting to get wrong because there is one discount.

## What they do not do

Being clear prevents a scoping mistake.

**They do not render anything.** A Function computes; it does not put a badge on a product page or a progress indicator in the cart. Storefront messaging is theme work or an app, and for threshold offers that messaging is most of the uplift.

**They do not give merchants a settings screen.** Not by default. You build that.

**They do not see everything.** A Function receives a defined input at a defined moment. Logic depending on data outside that scope needs it supplied, usually through metafields, and that is often the largest part of the work.

**They are not free to maintain.** Compiled code in a repository is code that somebody owns, upgrades against platform changes, and debugs when it misbehaves.

## Build for configuration from the start

The most common regret after moving discount logic to Functions, and it is entirely avoidable.

Under Scripts, a merchant could adjust a threshold themselves in the admin. Under Functions the logic is compiled, so a hardcoded threshold means every pricing tweak is a development ticket.

The fix is to separate logic from parameters. Thresholds, qualifying product sets, gift SKUs and date ranges should be read from metafields, exposed in the admin, and editable by whoever runs promotions.

## Configuration worth exposing
- Threshold values, per tier
- Qualifying products or collections, as a reference rather than hardcoded ids
- The gift or reward product
- Start and end dates
- Whether the offer is currently active, as a simple switch
- Any exclusion list

Do this and merchants keep the control that mattered while you keep the version history that was missing. Skip it and you have traded one bottleneck for another.

## Validate the inputs

A practical point that causes real incidents.

Once configuration lives in metafields, someone will eventually enter a value the Function does not expect — a blank threshold, a deleted product reference, a date in the wrong format, a negative number.

Decide explicitly what the Function does with nonsense, because the default behaviour is usually to emit no discount, silently. That is the worst failure mode available: no error, no alert, and orders completing at full price while everyone believes an offer is running.

## Instrument it, because failures are silent

Following directly from the above.

The characteristic Function failure is not a crash. It is a discount that quietly stops applying because a condition was subtly wrong or a metafield changed. Nothing errors. The only signal is margin that looks slightly too good, which nobody investigates.

Monitor the proportion of orders receiving each expected discount, and alert when it moves sharply. This costs an afternoon and is the only reliable defence. Every merchant who lost money to the Scripts deprecation lost it because nothing was watching that number.

## Testing a Function before it touches real money

Discount logic is the one place where a bug charges the wrong amount to a real customer, so the testing bar is higher than for most code.

**Test with historical carts.** Take twenty genuine past orders that your intended offer would have affected and confirm the Function produces the outcome you expect on each. This catches the edge cases a specification written from memory always misses — the order with a gift card, the one with mixed currencies, the fifty-line wholesale basket.

**Test the boundaries explicitly.** One unit below the threshold, exactly at it, one above. Off-by-one errors in discount logic are both common and expensive, and they are invisible in casual testing because nobody shops at exactly the boundary by accident.

**Test the combinations.** Every other discount that could be simultaneously active, including codes still circulating from campaigns nobody remembers.

**Test through every checkout path.** Standard flow, and a completed order through each accelerated method you have enabled. This is the whole reason to use a Function, so verify it rather than assuming.

**Test with an empty and an enormous cart.** Functions run within execution limits, and logic comfortable on a five-item cart may not be on a fifty-item one. The carts that break are disproportionately your largest orders, which is the worst possible selection.

> **Watch order-level margin for the first fortnight**
> 
> After deploying, the number to watch is not whether the discount applies but what you earned per order. A Function that over-applies looks like healthy revenue and unhealthy margin, and margin is the only place it shows up early enough to matter.

## When to reach for one

**Use native** for straightforward offers. It is free, tested, and holds through every checkout path.

**Use an app** for standard mechanics that need storefront messaging. You are mostly paying for the badges, the progress indicator and not having to commission a build.

**Use a Function** when the outcome cannot be expressed otherwise, when apps are conflicting over the cart, or when the subscriptions for one outcome have grown past the cost of building it once.

These are not exclusive. A common and sensible arrangement is a Function computing the discount and an app or theme section handling the storefront messaging, because each is doing what it is good at. What causes trouble is two things both computing pricing — a Function and a cart-manipulating app active simultaneously will eventually disagree, and the disagreement surfaces at checkout on a real order.

If you do migrate from an app to a Function, remove the app rather than leaving it disabled. Disabled apps frequently leave theme code behind that continues loading, and an app that can be re-enabled by someone who does not know about the Function is a genuine risk during a busy period.

For discount strategy and what each mechanic does to margin, see [promotions and offers](/category/promotions-offers). The Scripts migration specifically, and the wider development picture, are covered in [Shopify development](/category/shopify-development).

**Offer logic that behaves at checkout**
ByteInfy builds Shopify discount, delivery and payment logic with Functions — configuration exposed in the admin, and monitoring so silent failures do not stay silent.

[Start a project](https://byteinfy.com/#contact)

## FAQ

### What are Shopify Functions?

Shopify's supported mechanism for customising platform behaviour with your own code — discounts, delivery options, payment methods, cart validation.

### Do I need Shopify Plus to use Functions?

Discount Functions are available beyond Plus, which is a genuine widening compared with legacy Scripts, and it is the main reason smaller merchants can now express logic that used to be enterprise-only.

### When should I use a Function instead of an app?

When your offer cannot be expressed by native discounts and no app implements it correctly, when several apps are fighting over the cart, or when app subscriptions for one outcome have grown past what a build would cost.

### Why do Functions hold through Shop Pay when apps sometimes do not?

Because they apply at the platform level rather than by modifying the cart.

### Can merchants change a Function's settings themselves?

Only if you build for it. The logic is compiled and not editable in the admin, so thresholds, product sets and dates should be read from metafields and exposed in the admin.
