Problem:
Stores selling in multiple markets needed to show shoppers only the variants actually available in their region. Shopify's native variant picker has no region awareness, and asking for browser location permission pushes most shoppers away.
Solution:
A Cloudflare Worker that detects the shopper's active market from the Shopify context, checks inventory by location, and disables size and color swatches independently. A sold out colorway does not imply the whole product is gone.
How it works:
The filter reads the active market from the Shopify context, with a URL parameter override and a country code fallback list for EU markets. It maps that market to specific Shopify location IDs and calls a Cloudflare Worker for per location stock data. Size and color availability are evaluated separately so a disabled option reflects that specific combination, not the whole product. A MutationObserver watches for product cards loaded by infinite scroll or quick buy panels and applies the filter to those too, without a page reload. Thirteen different fallback strategies handle variant ID detection across different theme setups, keeping the filter working regardless of future theme changes.
Tools: