Shopify Functions: custom discounts and checkout logic

How custom logic runs inside Shopify's checkout without replacing it, what functions can do, and when they beat an app.

3 minread 692words last updated

The short answer

Shopify’s checkout is deliberately closed: stores do not replace it, and that is why it is fast, secure and trusted. Functions are how custom logic gets inside it anyway. A function is a small piece of your own code that Shopify runs at a defined point in the checkout: calculating a discount, customising shipping options and rates, showing or hiding payment methods, validating the cart against a business rule, adjusting delivery options. It runs on the platform’s infrastructure, within strict limits, without a script on the storefront and without touching the checkout’s integrity. Functions replace the older approach of scripts and third-party apps for rules the store owns, and they are code: in a repository, deployed through an app, tested and maintained.

What functions can do

TypeExamples
DiscountsTiered pricing by quantity; buy several get the cheapest free within rules; discounts for customer groups; exclusions and stacking rules; automatic offers without codes
Shipping customisationRename, reorder, hide or add delivery options based on the basket, the customer or the destination; rates that depend on contents
Payment customisationHide a payment method for certain orders, customers or values; reorder methods per market
Cart and checkout validationBlock checkout when a business rule is broken: quantity limits, incompatible items, restricted destinations, missing required products
Delivery and pickupAdjust delivery options and pickup availability by rule
Order routing and fulfilmentInfluence where an order is fulfilled from

Building and running them

  1. Write the rule precisely with the business: conditions, effects, exclusions, priority against other offers.
  2. Implement the function in a supported language, inside an app in your repository.
  3. Test it with the platform’s tools against realistic carts, including the edge cases: empty cart, mixed collections, existing codes, multiple currencies.
  4. Deploy through the app, privately for one store or as part of a public app.
  5. Configure the function’s inputs where the app exposes them: thresholds, collections, customer groups.
  6. Monitor the function’s runs and errors, and re-test when the platform updates the extension’s API version.

When functions beat an app

When the rule is specific to your business and no app models it exactly. When an app that approximates it injects scripts on the storefront or replaces parts of the cart. When margin depends on the rule being exactly right. When you want the logic in your own repository, versioned and testable. Apps still make sense for common, configurable needs; functions are for the rules you own.

What this means for you

Functions let your store’s own rules run inside the checkout, fast and safely, without scripts or a replaced checkout. Use them for discounts, shipping, payment visibility and validation that are specific to your business. Treat them as code: specified precisely, tested against edge cases, kept in your repository, maintained as the platform evolves. They are how a store gets custom checkout logic without giving up the checkout’s speed and trust.

Written by the CivSec S.M.A.R.T team

We build and run websites, software and AI systems for businesses. We write about what we see in that work, in plain language, and we update articles when things change.

Last checked . Spotted something outdated? Tell us.

Frequently asked questions

What can a function do that a discount code cannot?

Implement rules: buy three get the cheapest free within a collection, tiered pricing by quantity, discounts for a customer group, exclusions, stacking rules, a shipping rate that depends on the basket, hiding a payment method for certain orders, blocking a cart that breaks a business rule. Discount codes are fixed offers; functions are logic you write.

Do functions slow the checkout?

No, by design: they run on Shopify's infrastructure within strict limits, not as scripts in the browser. That is the point of the model: custom logic in the checkout without the performance and security cost of storefront scripts or checkout replacements.

Do we need a developer for functions?

Yes. Functions are code deployed through an app, written in the languages Shopify supports, tested and versioned. Some apps package common functions behind a configuration screen; for rules specific to your business, a developer writes and maintains them, and they live in your repository like any other code.

Sources

  1. Shopify developer documentation: Shopify Functions (accessed 2026-09-12)