Coming soon: Blockly Checkout Customizer — validation rules, upsells & checkout analytics.Get early access
Tutorial

Restrict Shopify Checkout by ZIP or Postal Code

Only deliver to certain areas, or need to exclude a few? Learn how to restrict Shopify checkout by ZIP or postal code with server-side rules, clear messages, and matching that handles real-world formats.

Restrict Shopify Checkout by ZIP or Postal Code

You deliver fresh flowers within 20 miles of your shop. Or your furniture courier covers three states and nothing else. Or a handful of remote postal codes cost more to reach than the order is worth. Either way, you need checkout to say no to addresses outside your area, before the customer pays and before you have to refund.

Shopify gives you shipping zones, but zones work at the country and region level. When the real boundary is a list of ZIP or postal codes, you need a different tool. This tutorial covers how to restrict Shopify checkout by ZIP code, the matching details that trip people up, and rule examples you can adapt.

Why ZIP-level restrictions matter

Postal codes are the most precise boundary most stores can work with. Common reasons to restrict by them:

  • Local delivery. Your own drivers only cover certain neighborhoods.
  • Perishables. Food, flowers, or chilled goods must arrive within a time window that only nearby areas can meet.
  • Carrier coverage. A freight or white-glove partner only serves specific regions.
  • Legal restrictions. Some products can't be sold or shipped to certain local jurisdictions.
  • Cost control. Remote or island postal codes carry surcharges that make some orders unprofitable.

Without a checkout rule, each out-of-area order becomes a refund, an apology email, and a customer who may not come back.

Your options on Shopify

Native shipping zones and local delivery

Shopify's shipping settings let you define zones by country and, in many countries, by state or province. The built-in local delivery option also supports a delivery area defined by postal codes or a radius. That works well if local delivery is your only method. But if a customer outside the area can still see a standard shipping rate, they can still check out. Native settings control which rates appear, not whether checkout is allowed.

Theme-level ZIP checkers

Some stores add a "check if we deliver to you" widget on the product page or cart. It's a good customer experience, and worth keeping. But it's informational. Nothing stops a customer from skipping it, using an express checkout button, or entering a different address at checkout.

Shopify Functions

Two Function types solve this properly:

  • Cart and Checkout Validation blocks checkout with an error when the shipping postal code is outside your rules.
  • Delivery Customization hides specific delivery options for certain postal codes, so a customer might lose express shipping but still check out with standard.

Both run server-side and apply to every path into checkout. Public apps using them work on all plans. See our checkout validation rules guide for more background.

Allowlist or blocklist?

Before building anything, decide which direction your rule runs.

ApproachHow it worksBest for
AllowlistOnly listed codes can check outLocal delivery, perishables, small service areas
BlocklistListed codes are blocked, everything else allowedA few remote or restricted areas
Hide optionsCodes lose specific delivery methodsPartial coverage, such as no express to islands

An allowlist is safer when your area is small, because new or unexpected codes are blocked by default. A blocklist is easier when you serve almost everywhere.

Step-by-step setup

  1. Collect the exact list of codes you serve or exclude, ideally from your carrier or delivery partner.
  2. Decide whether you need exact matches, prefix matches, or ranges (see below).
  3. Choose the scope. Should the rule apply to all products, or only some? All countries, or one?
  4. Choose the action: block checkout, or hide specific delivery methods.
  5. Write the customer message.
  6. Test with codes inside, outside, and on the edge of your area, plus a few typos.
  7. Launch and watch for support questions from customers who think they should be in range.

Matching postal codes correctly

Postal code matching looks simple until real addresses arrive. A few rules keep it reliable.

Normalize first. Convert to uppercase and remove spaces before comparing. "sw1a 1aa", "SW1A1AA", and "SW1A 1AA" should all match the same rule.

Handle ZIP+4. US customers may enter "94107-1234". Compare only the first five digits unless you deliberately need ZIP+4 precision.

Keep leading zeros. ZIP codes in parts of the US start with 0. Store and compare codes as text, not numbers, or "02134" becomes "2134" and never matches.

Exact vs prefix matching. Prefix matching is powerful but easy to get wrong.

RuleMatchesWatch out for
Exact 1000110001 onlyMissing nearby codes
Prefix 10010001 through 10099Includes codes you may not serve
Prefix SW1SW1A, SW1E, SW1P and moreUK outward codes vary in length
Prefix M5Toronto codes starting M5Canadian codes need the letter pattern

International formats differ. US ZIPs are five digits, Canadian postal codes alternate letters and numbers, UK postcodes vary in length, and many countries use four or six digits. If you ship to several countries, always pair a postal code rule with a country condition, so "1000" in one country doesn't accidentally match "1000" in another.

Rule examples

  • Local delivery only. Condition: shipping postal code is NOT in [10001, 10002, 10003, 10011]. Message: "We currently deliver only to a few Manhattan neighborhoods. Please enter an address in our delivery area or choose store pickup."
  • Perishables need nearby codes. Condition: cart contains a product tagged perishable AND postal code does not start with 941 or 940. Message: "Fresh items can only be delivered within the Bay Area. Remove fresh items to ship elsewhere."
  • Block remote areas. Condition: country is US AND ZIP starts with 995, 996, 997, 998, 999, or 967, 968. Message: "We can't ship to Alaska or Hawaii yet. We're working on it."
  • Hide express for islands. Action: hide the "Express" delivery option when postal code is in your island list. No error; customer sees standard shipping only.

If you use local delivery alongside standard shipping, the hide approach is often the gentlest. It's the same idea as in our guide to hiding shipping methods with Shopify Functions.

Pitfalls and edge cases

Outdated lists. Postal code boundaries change, and new codes get created. Review your list periodically against your carrier's coverage.

Pickup orders. If customers can pick up in store, a postal code rule shouldn't block them. Scope the rule to shipping or delivery methods only.

Typos. A customer typing an extra digit gets blocked with a confusing message. Mention the code they entered in your message context, or invite them to double-check it.

Message tone. "Address not allowed" feels like rejection. Explain the delivery area and, if possible, what to do instead, such as choosing pickup or contacting you.

Express checkouts. Always test with Shop Pay and other accelerated buttons to confirm the rule triggers when the address comes from a wallet.

Doing it with Blockly Checkout Customizer

Blockly Checkout Customizer, launching soon on the Shopify App Store, lets you build postal code rules without code. Add a list of codes or prefixes, choose whether it's an allowlist or blocklist, optionally combine it with country, product, or delivery method conditions, and pick the action: block with a message, or hide specific delivery options. Rules run as Shopify Functions, so they apply across every checkout path.

The takeaway

Shipping zones decide which rates appear. ZIP-level checkout rules decide who can actually check out. Pick allowlist or blocklist based on how big your area is, normalize codes before matching, be careful with prefixes, always pair postal codes with a country, and prefer hiding a delivery method over blocking when partial coverage will do. Your delivery promises stay realistic, and customers find out before they pay rather than after.

Up nextSet a Minimum Order Value on Shopify Checkout (Without Losing Sales)

Related articles

More tutorial articles →
Free forever plan

Ready to protect
your store?

Join 5,000+ Shopify merchants. Install in 30 seconds and block your first bad actor today.

  • No credit card
  • 5-minute setup
  • Cancel anytime