Question

I'm trying to implement a JavaScript solution in Shopify to match my customer's current location (by country.code using http://freegeoip.net/json) against an array of countries that my shop delievers too.

What I need to complete this is a list of country codes for all the countries in my 'Regions and Taxes' tab in JSON format that I can then use in my JavaScript file.

Just to (potentially) make it slightly trickier, we are going to have FIVE different shops each with different regions against each shop but all using the SAME set of templates uploaded from a single source control. So any code I write needs to be universal on all stores (i.e fetch the relevant JSON object to that shop). I can then either show people a country selector or not, depending if they are on the correct site

Is this possible Shopify / JavaScript gurus?

Thanks :-)

Was it helpful?

Solution

The Shopify API gives you access to a list of all countries listed in your 'Regions and Taxes' tab. You can find a detailed explanation of the API on the Shopify API page. This list includes all configured parameters for a country (taxes, shipping_rates).

There's one gotcha: this API is not 'public' accessible. If you want to use the output of this JSON within your shop, you have to make it 'public' first. You could for example create an App or proxy to accomplish this.

If you're only interested in Shipping rates, you can also use the Shopify's AJAX API GET /cart/shipping_rates.json to get an estimated shipping rate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top