Store Selected Region in the Storefront
Persist and retrieve the customer's selected region.
On this page
In this guide, you'll learn how to store a customer's selected region in your storefront, then retrieve it for later use.
Why Select and Store Region?
Prices, taxes, and available payment methods vary between regions. Customers should see the correct amounts for their country.
The Aiminaabee store code (NEXT_PUBLIC_DEFAULT_STORE_CODE) is not a region. Do not persist a country ISO as the store code.
Next.js: country in the URL
The Next.js template puts the customer's country in the route: app/[countryCode]/(store)/….
- List regions with
sdk.store.region.list(storeCode). - Map each region's
countries[].iso_2to that region. - Resolve
getRegion(storeCode, countryCode)from the URL param. - Pass
region.idasregion_idwhen listing products or creating/updating the cart.
When the customer switches country, navigate to /{newCountry}/… and let getOrSetCart update the cart's region_id if it changed.
ts
See Build a Next.js Storefront and List Regions.
SPA: persist a region ID
If you are not using URL-based countries, show the region list from List Regions and persist the chosen region's ID (cookie preferred over localStorage).
Retrieve it later with the Retrieve Region API route:
ts
Region React Context
A client RegionProvider is for SPAs. On Next.js, resolve the region on the server from [countryCode]. See Region React Context.