Shopify Functions Examples: 8 Real Use Cases and How to Build Them

Shopify Functions let you replace or extend Shopify’s backend logic with your own code. The most common examples are custom discount types, bundles sold as one unit, renamed or reordered delivery options, hidden payment methods, and checkout rules that block bad orders. This guide walks through eight concrete examples, then shows how to build one and what to know before you ship it.
TL;DR
- A Shopify Function takes JSON input from a GraphQL query, runs your logic compiled to WebAssembly, and returns JSON operations for Shopify to carry out.
- Practical examples cover discounts, cart transforms (bundles), delivery customization, payment customization, validation, order routing and local pickup.
- Public apps with functions work on any plan, but custom apps with Function APIs require Shopify Plus.
- Build with Shopify CLI templates, test with
app devlogs, and keep functions fast, because they run inside the purchase flow.
Table of Contents
- What Shopify Functions are and how they run
- Eight Shopify Functions examples that solve real problems
- Examples at a glance
- How to build your first function
- Testing, debugging and performance
- Plans, access and where functions show up
- A practical order of operations
- Our perspective
- Get help building functions that fit your stack
- FAQ
- Sources
What Shopify Functions are and how they run
Shopify describes Functions as a way to customize backend logic through Function Targets, which are the points where your code plugs in. Each function has three parts:
- Input: a JSON object produced by a GraphQL input query you write. You ask only for the cart, customer or metafield data the logic needs.
- Logic: code in any language that compiles to WebAssembly. Rust and JavaScript templates are available.
- Output: a JSON document describing operations, such as “apply 10% to this line” or “hide this payment method”.
Shopify calls your function as needed during the customer journey. You never call it by URL, and it cannot make network requests of its own, so everything it needs has to arrive in the input.
That last point shapes every design decision. If a rule depends on data outside Shopify, you sync that data into a metafield first, then read it in the input query. Our write-up on Admin versus Storefront GraphQL decisions covers how to think about where that data should live.
Where functions sit in checkout
According to the Function APIs reference, functions execute in a defined sequence: cart lines, cart transform, cart line discounts, discounts, fulfillment groups, fulfillment constraints, order routing, delivery methods, pickup point and local pickup generators, delivery customization, delivery discounts, payment methods, payment customization, verification, and cart and checkout validation. Knowing the order helps you debug. A bundle created by a cart transform exists before a discount function sees the cart, for example.

Eight Shopify Functions examples that solve real problems
Shopify’s own documentation lists the practical uses: creating a new discount type, hiding a payment option, renaming a delivery option, blocking checkout for an oversized order, choosing a different order location, grouping products as one unit and generating local pickup options. Here is how each plays out in a store.
1. Tiered quantity discounts
The classic example. Buy 5 or more, get 10% off. Buy 10 or more, get 20% off. The Discount Function API gives you one schema where a single function handles one discount, code-based or automatic, and can apply savings across three classes: product, order and shipping.
In practice your input query requests each cart line’s quantity, and the logic returns a product discount per qualifying line. Store the tier thresholds in a metafield so merchandisers can change them without a deploy.
2. Collection-based order discount
Give 15% off the order subtotal only when the cart contains an item from a particular collection. The input query asks which lines belong to the collection, and the output applies an order-level discount. This is a good first function because it touches only one discount class.
3. Free shipping with conditions
Because the same Discount API covers the shipping class, one function can offer free shipping when the cart has a certain mix of products. Shopify’s Build a Discount Function tutorial walks through a combined example: 20% off a cart line, 10% off the order subtotal and free shipping, all from one generated extension.
4. Bundles through cart transform
A cart transform function groups products and sells them as a single unit. Think of a skincare routine where three SKUs appear as one line with its own title and price, while inventory still decrements per component. Shopify maintains a tutorial for bundles among its use-case guides.
5. Delivery customization
Rename “Standard” to “Ground, 3 to 5 business days”, hide an expensive carrier option for heavy items, or reorder methods so the cheapest comes first. These are delivery customization functions. They change what shoppers see without altering the rates the carrier returns.
6. Hiding a payment method
The payments function tutorial shows how to hide a payment option based on the total value of the cart. It requires API version 2025-07 or higher. A common variant hides pay-on-delivery or invoice terms for first-time customers while keeping them for approved wholesale accounts.
7. Cart and checkout validation
Validation functions stop an order from proceeding when it breaks a rule. Shopify’s validation tutorial enforces product quantity limits, adds an admin UI extension so merchants can configure the limit, stores that configuration in metafields, and tests the result in both the checkout UI and the GraphQL Storefront API.
Another example from the documentation: blocking checkout when an order exceeds a maximum for customers who have no established order history. That is a practical fraud and risk control for high-ticket stores.
8. Order routing and local pickup
Order routing functions choose a different fulfillment location, for instance routing to the store closest to the buyer or the one with the most stock. Local pickup generators create pickup options at checkout. Shopify’s local pickup tutorial uses the template local_pickup_delivery_option_generator and supports Rust, JavaScript, TypeScript or Wasm.
This is especially relevant for multi-location brands, where each store has its own hours, stock and pickup rules.
Examples at a glance
| Use case | Function type | Typical input | What the output does |
|---|---|---|---|
| Tiered bulk pricing | Discount | Line quantities | Product discounts per line |
| Spend-based free shipping | Discount | Cart subtotal, lines | Shipping discount |
| Product bundles | Cart transform | Cart lines, component data | Merges lines into one unit |
| Rename or reorder shipping | Delivery customization | Delivery options | Rename, hide or move options |
| Hide a payment method | Payment customization | Cart total, customer | Hides a method |
| Quantity or order limits | Cart and checkout validation | Lines, customer history | Blocks checkout with a message |
| Closest-location fulfillment | Order routing | Locations, stock | Reorders location choice |
| Store pickup | Local pickup generator | Locations, hours | Creates pickup options |
How to build your first function
The documented path for a discount function is short. Per the Build a Discount Function tutorial:
- Create a Partner account and a development store.
- Create an app with Shopify CLI.
- Run
shopify app generate extension --template discount --name discount-function-rs. - Choose Rust, then review the generated configuration and input queries.
- Implement the logic.
- Test, then deploy.
The prerequisites are an app with the write_discounts and read_products access scopes, Node.js 22 or higher, and Rust installed. On Windows you also need Microsoft C++ Build Tools with the Desktop development with C++ workload.
What the scaffold gives you
The CLI generates the essential files: a TOML configuration, a GraphQL schema, a GraphQL input query and the function code. Adapting a Shopify example to your store usually means three edits: change the input query to fetch what you need, rewrite the logic, and update shopify.extension.toml for targets and configuration.
Shopify’s public Function examples repository is used by the CLI to generate extensions and is a good place to read finished code for each target.
Choosing a language
Anything that compiles to WebAssembly works, including Rust, AssemblyScript and TinyGo. When you use a language other than Rust, you specify the Wasm template option.
JavaScript is the easiest entry for most storefront teams. A few facts to plan around, from Shopify’s JavaScript for Functions page:
- The CLI compiles JavaScript with Javy, a JavaScript-to-WebAssembly toolchain.
- For smaller binaries and faster execution, use the latest CLI and version 2.0.0 or higher of the
@shopify/shopify_functionpackage. - You get ECMAScript 2020 and Javy globals. Browser APIs such as
setTimeout,fetch,cryptoandURLare not available, and neither are Node.js globals such asprocess.
Rust produces compact, fast binaries and suits logic that loops over large carts. JavaScript suits teams that already write it daily. Pick on who will maintain the code.
Testing, debugging and performance
When you run app dev, the CLI streams execution logs to your terminal and writes input, output and other execution details to the filesystem. Logs are also in the Dev Dashboard and are truncated after 1 kB, so log decisions, not whole carts.
Two habits pay off:
- Replay real inputs. Save the input JSON from dev runs and use it as fixtures in automated tests.
- Remember unit tests are not Wasm. Shopify notes that unit tests don’t run in WebAssembly, which in rare cases can produce different results than production, so it recommends automated testing built on known use cases and a final check in a dev store.
Performance deserves its own review. Shopify’s documentation stresses that functions run in key purchase flows such as discounts and checkout, and slow or resource-heavy functions can hurt the customer experience and potentially stop purchases. Keep input queries lean, avoid nested loops over every line against every rule, and precompute lookups into metafields. If you are also tuning the storefront side, our guide to Shopify performance and LCP covers the front half of the journey.
Plans, access and where functions show up
Plan access is the question that decides your approach. Stores on any plan can use public apps from the Shopify App Store that contain functions, but only Shopify Plus stores can use custom apps that contain Function APIs. The pickup point generator goes further: it is available only to custom apps on development stores or Plus stores.
For the merchant, functions surface in the admin in four places, according to the Shopify Help Center: Checkout for cart and checkout validation rules, Discounts for custom discount types, Shipping and delivery for delivery customizations, and Payments for payment method customizations.
If you are deciding what to build first, pair functions with the rest of your checkout work. Our piece on Shopify checkout optimization shows where discount, shipping and payment logic fit into conversion. For back-office reactions to orders, Shopify Flow handles automation that does not need to run inside checkout.

A practical order of operations
Teams that ship functions reliably tend to follow the same sequence:
- Write the rule in one sentence. “Hide invoice payment unless the customer is tagged wholesale.” If it takes a paragraph, split it into two functions.
- List the data. Which fields does the input query need? Which must be synced into metafields first?
- Pick the target. Match the rule to a discount, cart transform, delivery, payment or validation function, keeping the execution order in mind.
- Build in a dev store with CLI logs on and saved input fixtures.
- Add merchant configuration through metafields and an admin UI extension, so marketing can change thresholds without engineering.
- Deploy, then watch. Check checkout behavior on real orders and keep an eye on any drop in completion.
Our perspective
Most functions projects go wrong in the planning, not the code. A discount rule that lives in a function, a spreadsheet and a marketing email will disagree with itself within a quarter.
We treat functions as part of a connected system. The rule is defined once, the data feeding it is synced from the CRM or ERP into metafields, and the people who designed the logic stay involved while it is built and tuned. That is how we work: senior strategists embedded with your team, responsible for implementation rather than handing it to someone else.
For scaling stores, especially multi-location and enterprise commerce brands, we think the highest-value functions are the unglamorous ones: validation that protects margin, payment and delivery rules that match how you actually sell, and bundles that merchandising can edit without a ticket.
Service
Get help building functions that fit your stack
If your checkout rules are getting complicated, or you need functions wired into your CRM, inventory and reporting, we can build and maintain them with you. Our growth platforms work covers Shopify and BigCommerce engineering, and our engagements start with Core capacity at $3,500 to $5,999 per month. You can see all tiers on the pricing page.

To see the full range of what we build, from revenue operations to internal tools and automation, browse our capabilities.
FAQ
Do I need Shopify Plus to use Shopify Functions?
Not always. Stores on any plan can use public apps from the Shopify App Store that contain functions. Building and installing your own custom app with Function APIs requires Shopify Plus, per Shopify’s documentation.
Which language should I use to write a function?
Any language that compiles to WebAssembly works. Rust and JavaScript have official templates, and Rust is the language used in Shopify’s discount tutorial. Choose based on which language your team can maintain, and keep binaries small and fast.
Can a function call an external API?
No. In JavaScript functions, browser APIs such as fetch are not available, and Shopify calls functions with the input from your GraphQL query. Sync outside data into metafields ahead of time and read it in the input query.
How do I test a function before it goes live?
Run app dev to stream execution logs and write input and output details to disk, then replay those inputs in automated tests. Because unit tests don’t run in WebAssembly, finish with a check in a development store.
Sources
- About Shopify Functions
- Function APIs reference
- Function APIs, version 2026-01
- Discount Function API
- Build a Discount Function
- Create the payments function
- Create an admin UI extension for cart and checkout validation
- Build a local pickup options function
- Build a fulfillment constraints function
- JavaScript for Functions
- Test and debug Shopify Functions
- Generate pickup points
- Shopify Help Center: App extensions and functions
- Shopify function-examples repository