Dev.to WebDev 🛠 Dev 👁 2 📖 8 min read

Shopify Hide Shipping Method with a Delivery Customization Function (2027)

Shopify hide shipping method with your own Delivery Customization Function: hide Express for PO Box addresses, rename Standard for US buyers and keep the cheapest option first. Episode 6 of the Shopify Functions 2027 ser

Shopify hide shipping method with your own Delivery Customization Function: hide Express for PO Box addresses, rename Standard for US buyers and keep the cheapest option first. Episode 6 of the Shopify Functions 2027 series (API 2027-01). Real checkout on our dev store: with the customization off a US buyer sees Standard $19.90 and Express $25.32; with it on, Standard becomes "Standard - 3 to 5 business days", and a PO Box address gets only Standard.

3 quick fixes from this episode

Shopify Delivery Customization: No Express Shipping to PO Boxes

Shopify delivery customization with a Function: type a PO Box at checkout and Express disappears, a street address still gets it. Real checkout on our dev store, API 2027-01.
Full episode: {TUTORIAL_URL}

Shopify #ShopifyFunctions #ShopifyDeveloper

▶ 60-second video: https://youtube.com/shorts/MDW8KktRWGU

Shopify Shipping Customization: Rename a Shipping Method by Country

Shopify shipping customization with a Delivery Customization Function: US buyers see "Standard - 3 to 5 business days" instead of "Standard". The rule lives in the customization's metafield, so you change it without a redeploy.
Full episode: {TUTORIAL_URL}

Shopify #ShopifyFunctions #ShopifyDeveloper

▶ 60-second video: https://youtube.com/shorts/Rc2YrsNxjRY

Shopify Delivery Customization API: 3 Gotchas from a Real Checkout

Shopify delivery customization API gotchas from a real store: 'Access denied for deliveryCustomizations' until the app has write_delivery_customizations, early runs with no street address (address1 null), and option handles you must read every run, never hard-code.
Full episode: {TUTORIAL_URL}

Shopify #ShopifyFunctions #ShopifyDeveloper

▶ 60-second video: https://youtube.com/shorts/-pJpcrta4Rs

Step by step

Street address vs PO Box (0:00)

Same checkout, same cart. With a street address, the buyer gets Standard and Express. Type a PO Box, and Express is gone.

One Shopify Function decides that. This is episode six of Shopify Functions 2027: how to hide a shipping method, with a Delivery Customization Function. We hide Express when the address is a PO Box.

We rename Standard for buyers in the United States. We keep the cheapest option at the top. And I show you the real logs, a real error, and the limits from Shopify's docs.

Before: the customization is off (0:39)

First, the store without our Function. I switched the customization off. A twenty-four dollar tee, a New York address, and checkout offers two options: Standard, at $19 and ninety cents, and Express, at $25 and thirty-two cents.

Those rates come from the store's shipping settings. A delivery customization never creates rates and never changes prices. It only works on the options that already exist.

Here they are in the admin: Settings, Shipping and delivery. The International market, which includes the United States, has two options, Standard and Express. Our Function will hide, rename and reorder exactly these.

What a delivery customization can do (1:25)

A delivery customization Function runs in checkout. Shopify's docs list the cart page and the Storefront API as not supported. Accelerated checkouts are supported.

It returns a list of operations. Hide removes an option from the list. Rename changes the title the buyer sees.

Move changes the position of an option. And a store can activate up to twenty-five delivery customizations.

How checkout calls the Function (1:53)

Here is the flow. The buyer types or changes an address. Checkout gets the shipping rates from the store's settings, or from a carrier.

Then it calls our Function with those options, and our Function answers with operations: hide this one, rename that one, move this one up. The buyer only ever sees the final list. And it runs more than once.

In my test checkout, the logs show five runs: two before I typed a street, two with the street address, and one with the PO Box. Every change to the address can trigger a new run, so the Function must give the right answer every time, from whatever it gets.

Generate the Function (API 2027-01) (2:34)

shopify app generate extension, template delivery customization, flavor vanilla JS. Like every episode, the template writes 2026, oh seven, so we pin 2027, oh one, then run function schema and typegen. The handle is delivery rules.

We need it later, to switch the customization on. One target: cart, delivery options, transform, run. That is the whole config file: one target, one export.

The input query (3:03)

The input query. Checkout splits the cart into delivery groups, and each group has its own address. So we ask for the street lines and the country code.

Each group has its delivery options: the handle, the title, the cost, and the method type, like shipping or pickup. The handle is what every operation points at. Read it from the input on every run.

Never type a handle into your code. And last, a metafield on the customization itself. That is where our rules live.

Rules in a JSON metafield (3:38)

Here are the rules, stored as JSON on the customization. Hide any option with Express in its title, when the address is a PO Box. For the United States, rename Standard to Standard, three to five business days.

And keep the cheapest shipping option first. Because the rules are data, a merchant or your admin page can change them without deploying the Function again.

Hide Express for PO boxes (4:02)

Rule one. A regular expression that matches P O Box, with or without dots, and post office box. For each delivery group, we join both street lines and test them.

If there is no street yet, the test is false, and we hide nothing. If it is a PO Box, every option whose title contains Express gets a hide operation, pointing at its handle. We also remember the handle, so the other rules skip it.

That empty-street case matters. You will see it in the real logs.

Rename + cheapest first (4:34)

Rule two. If the address country matches the rule, find the option titled Standard and rename it. One limit from the docs: for carrier rates, Shopify puts the carrier name in front of the title, and rename can't remove it.

You could turn U P S Standard into U P S Standard Shipping, but not into Standard Shipping. Rule three. Take the shipping options that are still visible, sort them by price, and move each one to its index.

The cheapest goes to position zero. Shopify's rule: the cheapest shipping option must always be the one selected first. So reorder for clarity, never to push buyers toward a more expensive rate.

Switch it on: scope + deliveryCustomizationCreate (5:16)

To switch it on, the app needs the write delivery customizations scope. My first query, before I added it, failed with a real access denied error: the app was not allowed to see delivery customizations. Add the scope to the app's config file, restart app dev, and the dev store grants it.

Then delivery customization create, with the function handle, a title, enabled true, and the rules JSON in the same call. Use the function handle. It stays the same in every environment, so you never look up an ID again.

Real checkout: street address vs PO Box (5:49)

Now the real store, with the customization on. Same tee, into checkout. A New York street address: three fifty, Fifth Avenue.

Two options. Standard is now Standard, three to five business days, still nineteen ninety. Express is offered, twenty-five thirty-two.

The cheapest is first. Now I change the address to PO Box twelve thirty-four. Checkout runs our Function again.

Express is gone. Only Standard, three to five business days, is left. Exactly our rule.

The real logs (6:24)

These are the real logs from app dev, shortened. The first runs came in before I typed a street. Address one was null, only the country was known.

So no hide, just the rename and the moves. With the street address, the same three operations. With the PO Box: hide Express, rename Standard, and move Standard first.

The biggest run used about 400,000 instructions, out of the eleven million a Function may use. And to be honest about the moves: this checkout already listed the cheaper option first, so on our store they change nothing you can see. They matter when your options arrive in a different order.

Real runs become tests (7:02)

Those three real runs did not stay in the log folder. I copied them into the repo as test fixtures: the partial address, the street address, and the PO Box. Each fixture holds the real input and the real output.

On every push, GitHub Actions builds the Function, runs it with the PO Box input, and checks that all three fixtures still produce exactly the same operations. The run for this episode passed, in 3 minutes twenty. So if you change a rule later and break the PO Box case, the test fails before any buyer sees it.

On Windows, this also helps when Smart App Control blocks the local function runner, as I showed in episode two.

More rules, same pattern (7:46)

Once you have this pattern, other rules are small changes. You could hide Express for one province, or a range of zip codes. Both fields are in the address.

You could hide local pickup for some countries, using the delivery method type we already query. You could rename options with your own delivery promise for each market. Or hide an option when the cart contains a product with a certain tag.

For that one, you add the cart lines and the product tag to the input query. Each new rule starts there: if the Function needs a field, ask for it in the query first.

Gotchas: partial addresses, PO Box data, handles (8:22)

Gotcha one. Shopify's docs say your Function runs with a partial address before the buyer authorizes payment. Before that point, only the country, province, city and zip are available.

The docs' advice: if a field is null, don't filter the option. Our code does exactly that. Gotcha two.

The docs say PO Box detection is only supported for options from carrier services or third-party shipping apps. With Shopify's own rates, the data might not be there. On our store it was, but test it on yours.

Gotcha three. Read the handles from the input on every run. Never hard-code them.

And four. A cart can have more than one delivery group, so loop over all of them, as we did.

Recap (9:10)

Let's recap. A delivery customization Function runs in checkout, on the options that already exist. It hides, renames and moves them, always by handle.

Our rules live in the customization's own metafield, so they change without a redeploy. To switch it on: the write delivery customizations scope, then delivery customization create, with the function handle. And when an address field is still empty, don't filter.

The code is on GitHub, tag E P zero six, link in the description. Next episode: payment customization, hiding Cash on Delivery for big orders. See you there.

📖 The full written tutorial with every episode: https://www.wixob.com/shopify-hide-shipping-method/
📚 Course page: https://www.wixob.com/shopify-app-development-2026/
🔔 New episodes on YouTube: https://www.youtube.com/@fayyaz-ahmed-shopify-developer?sub_confirmation=1

Questions about the Shopify GraphQL Admin API? Ask in the comments — I answer every one.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.