Shopify fulfillment location rules with your own Fulfillment Constraints Function: fragile products must ship from the Warehouse, and gift sets ship together from one location. Episode 9 – the finale – of the Shopify Functions 2027 series (API 2027-01). Real store tests with two locations: without the rule the face roller ships from Shop location (two shipping rates); with it, only the Warehouse rate is left. A gift set that checkout split into 2 shipments becomes one. A fragile product with no Warehouse inventory shows "Shipping not available" – and a test order lands at the Warehouse in the admin.
Chapters
- 0:00 Fragile item: two rates become one (Warehouse only)
- 0:38 Before: a gift set in 2 shipments
- 0:53 What a fulfillment constraint does
- 1:23 Where it runs in checkout
- 1:44 Store setup: two locations, stock and rates
- 2:36 Generate the Function (API 2027-01, input_variables)
- 3:15 The rule's settings metafield
- 3:37 The input query: tags + locations by name
- 4:13 Rule 1: fragile items ship from the Warehouse
- 4:42 Rule 2: gift sets ship together
- 5:06 Switch it on: scope + fulfillmentConstraintRuleCreate
- 5:32 Real store: face roller + gift set
- 6:17 Impossible rule: Shipping not available
- 6:44 A real test order at the Warehouse
- 7:05 The real logs: 198K-343K instructions
- 7:32 Real runs become tests
- 7:53 Gotchas: stock, shipping rates, continue selling
- 9:05 Recap
- 9:38 The whole series: 9 episodes + code
Step by step (full walkthrough)
Fragile item: two rates become one (Warehouse only)
Same face roller, same New York address. Without our rule, two shipping rates. It ships from the shop.
With the rule, one rate is left, because only the warehouse may send it. This is episode nine, the finale of Shopify Functions 2027: Shopify fulfillment location rules, with a Fulfillment Constraints Function. Fragile products ship only from the warehouse.
Gift sets ship together, from one location. I show you what happens when a rule can't be met. And a real test order, the logs, the tests, and a wrap-up of the whole series.
Before: a gift set in 2 shipments
One more look at the store without our Function. Two serums that we sell as a gift set. Checkout says: your order will arrive in two shipments.
One serum from each location. For a gift, that's not what the merchant wants.
What a fulfillment constraint does
A fulfillment constraint Function runs in checkout. Its input is the cart's deliverable lines: the items that need shipping. For any line, it can say which locations are allowed to ship it.
Or it can say that a group of lines must ship from the same location. The docs are very clear on one thing: if a rule can't be met, checkout returns no shipping rates, and the buyer can't complete the order. We'll see that live.
A store can have up to twenty-five of these rules.
Where it runs in checkout
In the checkout order of Functions, it comes right after discounts. It decides where items may ship from. Then order routing ranks the allowed locations, and only after that do the shipping options exist, the ones we hid and renamed in episode six.
That's why this Function changes which shipping rates the buyer sees.
Store setup: two locations, stock and rates
Here's the setup. A second location called Warehouse, in Newark, New Jersey. I added it with the location add mutation, and gave it one shipping rate for the U S: Standard.
The shop location also has International Shipping. Then the products. The face roller is tagged fragile and is stocked in both places.
The face oil is also fragile, but has no record at the warehouse at all. And the two serums are tagged gift set. Niacinamide has stock at the shop, Retinol only at the warehouse.
That's why checkout split them. Two locations, two tags. The tags tell our Function which rule applies.
Here is the face roller's inventory in the admin: forty-three at the shop location, nineteen available at the warehouse. And the face oil: only the shop location. Remember this one.
Generate the Function (API 2027-01, input_variables)
shopify app generate extension, template fulfillment constraints, flavor vanilla JS. Like every time in this series, the template writes 2026, oh seven, so we pin 2027, oh one, then run function schema and typegen. The handle is fulfillment rules.
We need it to switch the rule on. One target: cart, fulfillment constraints, generate, run. And one line from episode four: input variables.
The values for our query come from a metafield on the rule. So the merchant's settings flow straight into the input query.
The rule's settings metafield
These are the settings, a JSON metafield on the rule. Which tags mean fragile. Which locations may ship fragile items, by name.
And which tags mean: ship together. Each key matches a variable in the input query. Change a tag or a location name here, and the Function uses it on the next checkout, without a redeploy.
The input query: tags + locations by name
The input query. Three variables, filled from that metafield. For every deliverable line: its id, and two yes or no answers, both from has any tag.
Fragile, and ship together. I gave them aliases, so the code reads like plain English. Then locations, filtered by name.
We ask for the warehouse, and Shopify gives us its location id. So no location id is hard-coded in the Function. It finds the warehouse by name on every run.
Rule 1: fragile items ship from the Warehouse
Rule one. A small helper for the product, and an empty list of operations. Collect the fragile lines, and the I D of each location we found.
If there are both, add one operation: deliverable lines must fulfill from. These lines, only from these locations. And if the cart has fragile items, but no location matched the name, we skip the rule and log a line.
A typo in the settings should never stop every checkout in the store.
Rule 2: gift sets ship together
Rule two. Collect the lines tagged as a gift set. If there are at least two, add: deliverable lines must fulfill from the same location.
Then return the operations. An empty list means no rules, and checkout behaves as usual. Notice there's no location in the same location operation.
Shopify picks one location that can ship all of them.
Switch it on: scope + fulfillmentConstraintRuleCreate
To switch it on, the app needs the write fulfillment constraint rules scope. I added it to the app config and restarted app dev, and Shopify granted it. Then fulfillment constraint rule create, with the function handle, the delivery method types, here only shipping, and the settings JSON in the same call.
Because we picked shipping, local pickup and local delivery are not affected by this rule.
Real store: face roller + gift set
Now the real store, with the rule on. The face roller, the same address. One rate: Standard, $19 and ninety cents.
That's the warehouse's rate. The shop's International Shipping is gone, because the shop is no longer allowed to send this item. The gift set.
Before, two shipments. Now there is one list of rates, for one shipment. These are the shop location's rates, so Shopify sends both serums from the shop.
Wait, Retinol has zero at the shop. In this store, the product keeps selling when it's out of stock, and in my test, a location with a zero stock record still counted. So keep your stock settings in mind when you test.
Impossible rule: Shipping not available
Now the face oil. It's fragile, so it must ship from the warehouse. But the warehouse has no stock record for it.
So checkout says: the product in your cart is not available for delivery to your location. And under Shipping method: shipping not available. The buyer can't order it at all.
The Function did exactly what we told it. The fix is in the store: stock the face oil at the warehouse, or take the fragile tag off.
A real test order at the Warehouse
Last proof: a real order. I placed one test order with Shopify's test gateway, so no money moved: the face roller and the gift set. Order twelve fifty-eight, unfulfilled, and the location badge says Warehouse.
The roller had to go there, and the gift set stayed together and joined it in one package.
The real logs: 198K-343K instructions
These are real runs from the app dev logs. A single serum with no tags: no operations. The roller and the face oil: must fulfill from the warehouse.
Same output for both; the difference is only the stock. The gift set: same location. And the order with the roller and the set: both operations.
The biggest run used about 343,000 instructions, out of the eleven million a Function may use.
Real runs become tests
Five real runs went into the repo as test fixtures. On every push, GitHub Actions builds the Function, runs it with the order's real input, and checks all five fixtures. All passed, with exactly the same instruction count as on the store.
So if a later change breaks the warehouse rule, the test fails before a buyer ever sees it.
Gotchas: stock, shipping rates, continue selling
Here is the first thing that went wrong for me. My first test of the roller showed this: shipping not available. The Function was right.
The new warehouse simply had no shipping rate for the U S yet. In this store, rates are set per market, so I added the warehouse as an origin of the Standard rate, and the rate appeared. So every location your rule points to needs stock and a shipping rate.
Gotcha one: every location your rule allows needs stock and a shipping rate for the buyer's address. Gotcha two: an impossible rule doesn't fall back. It blocks the order, like our face oil.
Start with one tagged product. Gotcha three: in my tests, a location with a zero stock record still counted, because the product keeps selling when out of stock. Gotcha four: we find locations by name, so a renamed location or a typo silently drops the rule.
Our code logs it instead of blocking. And five: the docs say constraint results can be cached for up to 15 minutes. In my tests, a new checkout picked up changes right away, but if you see an old result, start a fresh checkout.
Recap
Let's recap. A fulfillment constraint Function runs in checkout, on the deliverable lines. Must fulfill from: these lines may only ship from these locations.
Same location: these lines ship together, from one location Shopify picks. The tags and location names live in the rule's own metafield, and reach the query through input variables. And to switch it on: the write fulfillment constraint rules scope, then fulfillment constraint rule create, with the function handle.
The whole series: 9 episodes + code
And that's the end of the series. Nine episodes. We started with what Shopify Functions are, and wrote our first discount.
Then tiered discounts, and tiers the merchant edits in the admin. Bundles and mix and match, with Cart Transform. Hiding, renaming and reordering shipping methods, and then payment methods.
Checkout validation, and today, which location ships what. All the code is in one GitHub repo, with a tag for every episode, so you can check out the code exactly as it was in each video. Every Function uses API 2027, oh one, with real fixtures and a test run on every push.
The full playlist is linked in the description. If you need a Function built for your store or your app, my contact is there too. Thank you for watching the whole series.
See you in the next one.
The Shorts from this video
Shopify Split Shipping: 2 Shipments Become 1 with a Function
Shopify split shipping, controlled with a Fulfillment Constraints Function: two gift-set serums that checkout split into "2 shipments" now ship together from one location. Real store, two locations. If no single location can ship the set, checkout shows no shipping at all – so keep stock in sync. API 2027-01.
Shopify Shipping from Multiple Locations: Fragile Items Ship from the Warehouse
Shopify shipping from multiple locations: a Fulfillment Constraints Function sends products tagged fragile only from the Warehouse. Real store: before, the face roller ships from Shop location with two rates; after, only the Warehouse rate is left, and a test order lands at the Warehouse in the admin. API 2027-01.
Shopify Fulfillment Constraint Function Gotcha: Shipping Not Available
Shopify fulfillment constraint function gotcha: a rule says fragile items ship from the Warehouse, but the face oil has no inventory at the Warehouse – so checkout says "Shipping not available" and the buyer can't order. Fix: stock it there, or change the rule. API 2027-01.
🔔 New episodes every week on the YouTube channel. Need a custom Shopify app or API integration? Wixob Technologies builds them: info@wixob.com.