Shopify Functions 2027

Shopify Tiered Discounts with Shopify Functions (2027): 10% Off + Free Express Shipping

Fayyaz Ahmed

Shopify tiered discounts with Shopify Functions, built for real: spend $100 for 5% off, spend $150 for 10% off plus free Express shipping – one Discount Function, episode 3 of the Shopify Functions 2027 series (API 2027-01). We test it at a real checkout: $113 gives 5% off, $151 gives 10% off and Express drops from $25.30 to FREE – then we type a code that does not combine and watch what Shopify really does.

Chapters

  • 0:00 Intro: tiered discounts + free Express
  • 0:37 The promotion
  • 1:06 Two targets, one Function
  • 1:34 Discount classes
  • 2:01 Generate the Function
  • 2:42 Tiered order discount code
  • 3:43 Selection strategy: FIRST vs MAXIMUM
  • 4:16 Free Express shipping code
  • 5:20 Activate the discount
  • 5:50 Real store demo
  • 7:34 Discount combinations
  • 8:23 Automatic or code discount
  • 8:43 Common errors
  • 9:48 Recap

Step by step (full walkthrough)

Intro: tiered discounts + free Express

A 100 and fifty-one dollar cart. 10% off the order, and Express shipping is free. Both come from one Shopify Function: a tiered discount we write in about forty lines of JavaScript.

This is episode three of Shopify Functions 2027, and we go deep into the Discount API. One Function with two targets: the order total and the shipping options. Tiers built from candidates, conditions and a selection strategy.

A delivery discount that makes only Express free. And what really happens when a buyer types a code that does not combine.

The promotion

Here is the promotion. Spend a $100, and you get 5% off the whole order. Spend a 100 and fifty, and it becomes 10% off, plus free Express shipping.

We build it as one Discount Function, and the merchant's discount gets two classes: order and shipping. JavaScript, on API version 2027, oh one. The code is in the series repository, tag e p zero three.

Two targets, one Function

A Discount Function can have two targets, and Shopify calls each one separately. cart lines discounts generate run handles product and order discounts. That is where our five or 10% comes from.

cart delivery options discounts generate run handles shipping. That is where Express becomes free. Each target has its own input query and its own JavaScript function, but they live in the same extension and ship together.

Discount classes

Every discount that uses our Function has discount classes. There are three. Product discounts change cart line prices.

Order discounts take money off the order subtotal. Shipping discounts change delivery options. The classes are set on the discount, not in our code.

So our code must check them, and only return operations for classes it was given. That is the first line of both of our functions.

Generate the Function

We generate it like in episode two: shopify app generate extension, template discount, vanilla J S, name spend tiers. By the way, the CLI updated itself to version 5.2.1 during this run. The template still writes API version 2026, oh seven, so we change it to 2027, oh one.

The first targeting block is the cart lines target, with its own input query and export. The second block is the delivery options target. The discount template already includes both.

Then shopify app function schema, typegen and build, exactly as before.

Tiered order discount code

The order target. Our input query is tiny. We only need to know that the cart has lines.

And the discount classes. Notice: we do not ask for any prices. The tiers are checked by Shopify itself, through conditions.

Let me show you. The tiers are a plain list: a $100 for 5%, a 100 and fifty for ten. In episode four we move these numbers into a metafield, so merchants can change them.

First the guard: no lines, or no order class, means no operations. Then one candidate per tier. Each candidate has a message, a target, the whole order subtotal, a percentage, and a condition: order minimum subtotal.

And the selection strategy: maximum. Shopify checks every condition, throws away the candidates that fail, and applies the biggest one that is left. So the code never compares a price.

Shopify does it, with its own numbers.

Selection strategy: FIRST vs MAXIMUM

Which strategies exist depends on the operation. These come from the 2027 oh one schema. Order discounts allow first and maximum.

Product discounts allow all, first and maximum. Delivery discounts only allow all. With first, the order of your list decides.

With our list, first would pick the 5% tier, because it is listed first and its condition passes. Maximum picks the 10%. So for tiers, maximum is the safe choice: you can list the tiers in any order.

Free Express shipping code

Now the shipping target. This time we do need the subtotal. And the delivery groups, with every option's handle, title and method type.

Why ask for the subtotal here? Because delivery candidates have no conditions field. We checked the schema: message, targets, value, and an associated discount code.

That is all. So this time, our code checks the threshold. Same guard, for the shipping class.

Then the threshold. The amount arrives as a string, so we turn it into a number. Below a 100 and fifty: no operations.

Now the targets. The template discounts a whole delivery group. We go one level deeper: delivery option, by handle, and we keep only shipping options whose title contains express.

One candidate: a 100% off, on those options. Strategy all, the only one delivery discounts have. If no option is called Express, the list is empty, and we return nothing.

Keep that in mind, it comes back in the errors chapter.

Activate the discount

We activate it with discount automatic app create, like in episode two. The function handle is spend tiers. And the classes: order and shipping.

Without shipping, our second target would always return nothing. combines with: product discounts yes, other order and shipping discounts no. Remember that, we will test it at checkout.

The real response: status active, no userErrors.

Real store demo

Our development store. A ninety-five dollar canvas bag goes into the cart. $95.

Below every tier, so the cart shows no discount at all. Now an eighteen dollar face roller. A 100 and $13.

One candidate qualifies: 5% off orders over a hundred, minus $5 sixty-five. Then a thirty-eight dollar serum, and we go to checkout. A 100 and $51.

Now both candidates qualify, and maximum picks 10%: minus $15 ten. For shipping options, checkout needs an address, so we fill in a test address in New York. The shipping options load.

Express, normally twenty-five thirty, is free. Standard still costs nineteen eighty-eight, because our Function only targets Express. This is the real input of that checkout, from the shopify app dev log.

Subtotal one fifty-one, and two shipping options: Standard and Express. And our real output: one candidate, free Express over a 100 and fifty, targeting only the Express handle. That run used 344,000 instructions.

Measured on the real runs: the order target used 374,000 instructions, of an eleven million limit. The delivery target: 344 thousand. The module is three kilobytes.

On this Windows PC, Smart App Control still blocks function runner, so the local runs happen in GitHub Actions, like in episode two. And seven fixture tests pass, four of them built from real logs of today's store runs.

Discount combinations

Now a test most tutorials skip. The buyer types a store code, WIXOB fifteen: 15% off, and it combines with nothing. Shopify applied the code instead of our discount.

Minus twenty-two sixty-five, which is more than our fifteen ten. And look: Express is back to twenty-five thirty. Our free shipping went too.

The code combines with nothing. Our discount combines with product discounts only. They cannot stack, so the buyer gets one of them.

In our real checkout, that was the code, and our order discount and our free Express both went with it, because they belong to the same discount. If you want them to stack, both discounts must allow it: the code must combine with order and shipping discounts, and ours must combine with order discounts.

Automatic or code discount

One more choice. We made an automatic discount, so it applies by itself. The same Function can also power a code discount: discount code app create, with the same function handle.

Then the discount only runs when the buyer enters that code. Your Function code does not change. The merchant decides how the promotion is sold.

Common errors

Errors. This one is real. On our first checkout test, a US buyer saw International Shipping and Standard.

No option was called Express, so our Function correctly returned nothing, and nothing was free. On this store, shipping rates are set per market, so we set up an Express rate in the market our US buyers use. Matching by title is simple, but titles belong to the merchant.

In episode four we make it a setting. Always read the real input in the log before you blame your code. Here are the others.

The shipping discount never appears: the discount needs the shipping class. Free shipping not applied: read the option titles in the real input. Your discount vanishes when a code is used: set combines with on both discounts.

Another automatic discount wins: our store had an automatic free shipping over $75. We paused it for this episode, so the result you saw is ours. And a store can have at most twenty-five discount Functions active.

Recap

Let's recap. One Discount Function, two targets: the cart lines and the delivery options. Tiers are candidates with an order minimum subtotal condition, and maximum picks the best one.

Delivery candidates have no conditions, so we check the subtotal ourselves and target only Express. And combinations decide what the buyer really gets. The code is in the shopify functions 2027 repository, tag e p zero three, linked below.

In episode four, we make these tiers configurable, with metafields and a settings screen for the merchant. See you there.

The Shorts from this video

How to Create Tiered Discounts in Shopify with a Function (2027)

How to create tiered discounts in Shopify with a Function: one candidate per tier, an orderMinimumSubtotal condition each, and selectionStrategy MAXIMUM. Real cart: $113 gets 5%, $151 gets 10%.

Shopify Shipping Discount Function: Free Express Over $150

Shopify shipping discount function: the delivery target checks the subtotal itself (delivery candidates have no conditions) and returns deliveryDiscountsAdd for the Express option only. Real checkout: Express $25.30 becomes FREE, Standard stays $19.88.

Shopify Discounts Not Combining? What Really Happens at Checkout

Shopify discounts not combining? Real test: our automatic discount gave 10% off + free Express; a code that combines with nothing replaced it completely (-$22.65, Express back to $25.30). To stack them, both discounts must allow the combination (combinesWith).

🔔 New episodes every week on the YouTube channel. Need a custom Shopify app or API integration? Wixob Technologies builds them: info@wixob.com.