Shopify Functions: What They Are and When to Use Them
A developer's guide to Shopify Functions — what problems they solve, how they differ from Scripts and apps, and when to build one.
- 01What Shopify Functions are
- 02Functions vs Scripts vs apps
- 03When to build a Function
- 04Building your first Function
What Shopify Functions are
Shopify Functions are server-side WebAssembly modules that run inside Shopify's infrastructure at specific points in the commerce flow — primarily at checkout. They replace Shopify Scripts (which were Plus-only Ruby scripts) with a more capable, language-agnostic, and performant system.
Functions run on Shopify's servers, not yours. They receive a structured input (the cart/checkout state), execute your logic, and return a structured output (what to apply). There's no network call to your backend during execution — which makes them significantly faster than app proxy approaches.
Current Function APIs: Discounts (cart and order), Shipping, Payment customization, Cart Transform, Fulfillment Constraints, and Order Routing.
Functions vs Scripts vs apps
Shopify Scripts (being deprecated) were Plus-only Ruby scripts that ran at checkout. They were powerful but had no IDE support, no testing, and limited debugging.
Shopify Functions are the replacement: available on Plus and some non-Plus plans depending on the API, written in any language that compiles to WebAssembly (Rust recommended, JavaScript supported), with full local development and testing support.
Regular apps (making Admin API or Storefront API calls) are appropriate for things that happen outside the checkout flow — syncing data, building admin UIs, processing webhooks. If your logic needs to run at checkout time and affect the checkout (prices, shipping, payments), that's a Function.
When to build a Function
Build a Shopify Function when you need to: apply custom discount logic at checkout (volume tiers, BOGO, B2B pricing adjustments), filter or rename payment methods based on cart contents, filter or rename shipping rates, transform cart line items before checkout, or enforce order routing rules.
Don't build a Function when: the logic can be handled by Shopify's native automatic discounts or discount codes, the operation happens outside the checkout (use a webhook + app instead), or you need to call an external API during checkout (Functions can't make HTTP calls during execution — pre-load data into metafields or metaobjects instead).
Building your first Function
Start with the Shopify CLI: `shopify app generate extension --type=function`. Choose the Function API type (e.g., product-discounts). The scaffold generates the input/output types and a basic implementation.
Functions are tested with JSON input files that represent the checkout state. `shopify app function run` executes the function locally against test input and shows the output — no live store needed for unit testing.
Deployment: `shopify app deploy` pushes the Function to Shopify. It's then available to configure in the Shopify admin under the relevant section (Discounts, Shipping, etc.) — or via the Admin API if your app configures it programmatically.
Need help implementing this?
I build what I write about. If you need this implemented on your Shopify store, get in touch.
Discuss your projectReady to build this on your store?
Let's scope it.
I reply personally within 24 hours.