How to Build a Shopify Discount Function (Code and No-Code)

Every tutorial on this topic assumes you're a developer. Here's the actual code path, plus the faster route most merchants don't know exists.

Search "how to build a Shopify discount function" and every result assumes the same thing: you already know Rust or JavaScript, you have a Partner account, and you're comfortable in a terminal. That's the correct answer for a genuinely custom rule. It's the wrong answer for the majority of merchants who land on that search because Shopify Scripts stopped working and they need a replacement fast.

A Shopify discount function is a WebAssembly module, written in Rust or JavaScript through the Shopify CLI, that runs at checkout to apply custom discount logic to product, order, or shipping discounts. It replaced Shopify Scripts, which stopped executing entirely on June 30, 2026. There are two ways to end up with one: write it yourself, or install an app that already built one and gives you a visual way to configure it.

How do you build a Shopify discount function from scratch?

Building a custom Shopify discount function means scaffolding an extension with the Shopify CLI, writing the discount logic in Rust or JavaScript, and deploying it as part of a Shopify app. Shopify's own tutorial walks through the full sequence: use the CLI to add a Discount Function to an app, review the generated configuration, inspect the GraphQL input queries the function receives, write the function logic, deploy the updated app, then use GraphiQL to create a discount and wire it to your new function.

The mechanics in practice, condensed from that process and a few independent walkthroughs:

  1. Install the Shopify CLI and create a Partner account and development store.

  2. Run `shopify app generate extension --template discount` to scaffold a new discount function extension.

  3. Choose Rust or JavaScript. Rust compiles to smaller, faster WebAssembly; JavaScript has a shorter learning curve for most web developers.

  4. Write the function logic: it receives structured cart, customer, and order data as input and returns structured discount instructions as output.

  5. Build a metafield-backed configuration UI if merchants need to adjust settings (a threshold, a percentage) without redeploying code.

  6. Deploy the app, register the function, then create a discount in Shopify admin and attach your function to it.

  7. Test on a development store before activating on production.

One developer-facing walkthrough frames the whole thing as roughly 30 minutes for a simple product discount, assuming you already have your development environment set up. That estimate holds for a single, narrow rule. It does not hold once you need multiple condition types, several discount classes, or a UI a non-technical teammate can actually use.

Why did this replace Shopify Scripts in the first place?

Shopify Scripts ran inline Ruby code directly against the cart object, while Functions are precompiled WebAssembly modules that Shopify's infrastructure executes in a sandboxed, high-performance environment, and the two architectures are not compatible. Scripts were deprecated for good reason: they ran on Shopify's own servers with direct cart access, which created both a performance ceiling and a security surface Shopify didn't control. Functions receive structured input and return structured output, nothing more, which is why Shopify's Functions documentation describes them as running in under five milliseconds regardless of store size.

The tradeoff is development complexity. A Script was a snippet of Ruby dropped into an editor inside Shopify admin. A Function is a compiled module that needs a CLI, a Partner account, a deployed app, and a testing cycle before it touches a live cart.

Do you actually need to write a custom function?

No, not if your discount logic maps to a standard pattern like tiered pricing, BOGO, spend-threshold percentages, or shipping rules by country, since a free app already built the function and gives you a visual way to configure it. This is the part every code-first tutorial skips, because it's not a developer's problem to solve. Flowly: Discount Functions is exactly that: a free Subscribfy app built on the same discount function framework the tutorials above teach you to build from scratch, minus the Rust, the CLI, and the deploy cycle.

How do you configure a discount function without writing code?

Flowly replaces the code-and-deploy workflow with a visual canvas of three connected node types: Start, Condition, and Apply Discount. You wire a Condition node (cart subtotal, product tag, customer segment, and nine other fields, combinable through AND/OR/NOT) to an Apply Discount node (Percentage Off, Fixed Amount Off, Free Shipping, or Buy X Get Y), scope it to a discount class, and save. The rule syncs directly onto Shopify's native discount object the moment you save, so there's no separate deploy step and no metafield UI to build for merchants to adjust it later. Flowly's docs hub covers the exact sync mechanics and node behavior if you want the technical detail before building anything.

The tradeoff runs the other direction from custom code: you're limited to the twelve condition types and four actions Flowly supports. For the genuinely custom minority, a wholesale pricing model tied to draft orders, for example, the CLI-and-code path is still the only route in.

Custom code vs. a no-code function builder




Time to first live rule

Roughly 30 minutes to several days, depending on complexity

Minutes

Skills required

Rust or JavaScript, Shopify CLI, GraphQL

None

Cost

Developer time (internal or contracted)

Free

Flexibility

Fully custom, any logic

12 conditions, 4 actions, 3 discount classes

Merchant-editable after launch

Only if you build a metafield UI

Yes, by design

Best for

Non-standard logic (draft-order wholesale, loyalty-tier stacking)

Tiered pricing, BOGO, spend thresholds, shipping rules

FAQ

What language do you use to build a Shopify discount function?

Rust or JavaScript, through the Shopify CLI. Rust produces smaller, faster WebAssembly binaries; JavaScript has a lower barrier to entry for developers already working in the Shopify app ecosystem.

How long does it take to build a custom discount function?

A simple, single-condition product discount can take under an hour once your development environment is set up, according to one Shopify Functions walkthrough. Anything with multiple discount classes, a merchant-facing configuration UI, and real testing typically runs days, not hours.

Can I build a discount function without a developer?

Yes, for standard patterns. Tiered pricing, BOGO, free shipping by country, and spend-threshold discounts are all things Flowly's visual canvas covers without writing code, since it's built on the same discount function framework the custom path uses.

Is there a limit to how many discount functions I can run?

Yes, 25 active discount functions per store , according to Shopify's own Discount Function API documentation, whether built custom or through an app.

Do discount functions work on Shopify POS?

Yes. Shopify's Functions on POS changelog confirms discount functions now apply in-store the same way they apply at online checkout, which wasn't true of the older Scripts system.

Writing a discount function from scratch is the right call when your logic is genuinely custom. For everything else, download Flowly directly from the Shopify App Store and build your first rule on the same infrastructure the tutorials above teach, without touching a line of code, or book a call with Subscribfy's team if you're not sure which path your logic actually needs.

Image

Book a meeting with our sales team now!

Create predictable revenue from the customers you already have.