Skip to content
House of Marka
AppsServicesMarketplacesWorkInsightsCompanyStart a project
D2C & Growth5 min readBy

Shopify Functions Explained for Merchants: Discounts That Hold at Checkout

A plain-language guide to Shopify Functions: what a discount function is, why it runs at checkout, how it differs from Scripts, and what to ask a developer.

A Shopify Function is a small piece of code, delivered inside an app, that Shopify runs on its own servers while it works out a cart or a checkout. A discount function is the kind that decides which discounts apply and how much they take off. Because it runs inside Shopify and not in your theme, the price it produces is the price the shopper is charged. This guide explains what that means day to day, how Functions differ from Shopify Scripts and from apps that only change the price on screen, and what to ask a developer before you install anything that touches your prices.

What is a Shopify Function, in plain terms?

It is a rule that Shopify itself carries out. A developer writes the rule, packages it in an app, and you install the app. From then on, every time Shopify calculates a cart, it hands the function a description of that cart and gets a decision back.

You never see or edit the code. What you see is the settings screen the app gives you: which products, what threshold, how much off. The function reads those settings and applies them.

What does a discount function do?

It answers one question on each calculation: given this cart, what should be reduced, and by how much. Typical rules look like this:

  • Spend over a set amount and shipping is free.
  • Buy three of the same item and each costs less.
  • Add a particular product and a gift is added at no charge.
  • Buy items from a set together and the set is cheaper than its parts.

Shopify's built-in discounts cover the simple versions of these. A function lets an app express rules the built-in types cannot, such as several reward tiers on one cart or a mix-and-match bundle.

Why does it matter that it runs inside Shopify?

Because the cart and the checkout then agree. The cart your theme shows and the checkout page both ask Shopify for the total. If the discount lives inside Shopify, both get the same answer, since the same logic produced it.

There are two practical consequences:

  • No price jump at the last step. The number in the cart is the number at payment.
  • It does not depend on the shopper's browser. A slow connection, a script blocker or an error elsewhere on the page cannot stop the discount being applied.

How are Functions different from Shopify Scripts?

Scripts did a similar job in an older way. They were a tool for Shopify Plus stores: the merchant or an agency wrote a script, and it changed line prices, shipping or payment options at checkout. Shopify is retiring Scripts in favour of Functions.

For a merchant, the differences that matter are these:

  • Who maintains the code. A script belonged to the store, so the store had to keep it working. A function belongs to an app, and the app's developer maintains it.
  • How you configure it. Changing a script meant editing code. A function is configured through the app's settings.
  • Who can use it. Functions that arrive through an app are not reserved for Plus stores. What still needs Plus is covered in our guide to what each Shopify plan can customise at checkout.

If your store still relies on a script, list what it does in plain words.

How are they different from apps that change prices in the theme?

Those apps change what the shopper sees, not what Shopify charges. A script in the theme rewrites the price on the page or in the cart. Checkout knows nothing about it, so the app needs a second step to make the real price follow, often a discount code created on the spot or a specially built order.

That second step is where things go wrong:

  • The shopper types their own code and the app's code is replaced.
  • The theme script fails to load and the full price is charged.
  • The cart shows one total and checkout shows another, which shoppers notice at once. Our guide on why the cart total does not match checkout walks through the causes.

A function removes the second step. There is one calculation, and it happens where the money is taken.

What should you ask an app developer?

Ask how the price is applied before you ask about features. Six questions cover it:

  1. Is every discount applied by a Shopify Function, or are any of them shown in the theme and applied some other way?
  2. How does the discount appear to the shopper at checkout and on the order?
  3. How does it combine with discount codes and with my other automatic discounts?
  4. If two rules could apply to the same item, which one wins?
  5. Can I see why a particular cart got its total?
  6. What is left in my theme if I uninstall?

A developer who uses Functions can answer the first question in one sentence. Marka Cart Drawer is an example: its rewards, free gifts, cart-only deals, bundles and volume discounts are applied at checkout by a Shopify discount function, and its Discount Explainer runs that same function to show why a cart or order got its price.

What can still go wrong?

A function puts the calculation in one place. It does not make your offer rules sensible. The usual problems are set-up problems:

  • Two apps each discount the same product and the combination settings allow both, or neither.
  • A discount code is allowed to stack on an automatic discount you meant to be exclusive. Decide this on purpose; our piece on whether to show a discount code box in the cart covers the trade-off.

Place a test order for every offer you run, including one with a code entered.

A short checklist

  1. List every discount your store runs and note where each is applied: built-in discount, function, script or theme.
  2. Ask each discount app the six questions above.
  3. Review combination settings so stacking is a decision and not an accident.
  4. Place test orders with and without a discount code and compare cart, checkout and order totals.
  5. If a script is still in use, write down its rules in plain language as a replacement brief.

For what belongs in the cart, read our guide to Shopify cart drawers and order value. If you want cart offers that are priced by a discount function from the start, the features and plans are on the Marka Cart Drawer page.

Work with us

House of Marka is the applied-AI and commerce engineering studio of Marka Modern Retail Private Limited. We research, advise and then build — for merchants and enterprises in the US, UK and Europe.