Problem:
Customers in the EU were accidentally purchasing US-only stock, leading to high refund rates and fulfillment errors across regions.
Solution:
A Cloudflare Worker detects the user's region via IP headers and queries the Shopify GraphQL API to disable swatches and the Add to Cart button for any variant not stocked in the nearest warehouse.
How it works:
The Worker intercepts every storefront request, reads the IP-based market header, and queries the Shopify Admin GraphQL API for variant-level inventory at each regional warehouse. The result is passed to a custom JavaScript asset on the frontend, which disables color swatches and the Add to Cart button for any unavailable variant, all before a single click.
Tools: