Re: How to change user localization by url param

Solved

How to change user localization by url param

deMenezes
Tourist
8 0 4

I can change the user location by localization form:

 

https://shopify.dev/docs/api/liquid/tags/form#form-localization

 

But this way enforces the user submits the form to set the country.

 

I want to change user location directly by url parameter, something like this:

 

  • If the user access store.com/?country=us, he's from US
  • If the user access store.com/?country=fr, he's from French

 

It doesn't matter how it finds that particular URL, I just want to set the country that way.

 

It's possible?

Accepted Solution (1)

coleatkinson
Shopify Staff
141 13 78

This is an accepted solution.

Hi there, yes, it is exactly as you have written: https://help.shopify.com/en/manual/markets/international-domains/directing-customers/deep-links

Cole | Product @Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

View solution in original post

Replies 6 (6)

coleatkinson
Shopify Staff
141 13 78

This is an accepted solution.

Hi there, yes, it is exactly as you have written: https://help.shopify.com/en/manual/markets/international-domains/directing-customers/deep-links

Cole | Product @Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

deMenezes
Tourist
8 0 4

This is so **bleep** perfect!

 

My Product Owner will be very happy lol

 

Thank you very much.

Fabian_fg
Shopify Partner
7 0 0

Hello Cole , we recently implemented this, but when we used the deep links, all our prices that were returned from the Shopify Ajax APIs (Cart, recommended products, predictive search) were shown in the right currency, but default currency amount.

Example: The price displayed in all the components using the APIs after switching to canada in a store that has euro prices as default: 109 CAD (euro value) instead of 160,62 CAD (correct CAD value)

This made every price rendered through liquid correct, but the ones pulled from the API incorrect.

We went away from the deep links because of that to a custom solution using the localization form, but we'd love to use the deep links if the issue was solved. If this worked correctly, we could also switch countries directly and, on top of that, utilize custom URL parameters on the same shop domain and persist parameters across our different shop domains.

Could you please check, if that has happened to anybody else, or have an idea on how to fix this?

coleatkinson
Shopify Staff
141 13 78

Can you DM me with the store and more details around the API call please? I will get this in front of the right people to diagnose

Cole | Product @Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Peter-Coolen
Shopify Partner
2 0 0

I've tried to use this with the checkout (Shopify Plus) but it's not working. 

 

?locale=fr-BE is only setting the correct language, not the country.
?country=BE isn't doing anything for me.

 

Can you help me? 

st_consult
Shopify Partner
17 1 7

I have issues with the URL parameter for countries, too. This seems to be in combination with language subfolders:

 

Assume I have Canada (CA) as currently selected country and French as language. Then my URL looks like this: https://my-shop.myshopify.com/fr. When I set the URL parameter to switch the country, like in https://my-shop.myshopify.com/fr?country=BE, the page reloads and correctly shows the new country and currency. But as soon as I don't use the parameter again (like this: https://my-shop.myshopify.com/fr), Canada is shown again. There is no permanent assignment.

 

This behavior is only shown in a productive/merchant shop and only if I have a language subfolder. In my dev environment or in production with no subfolder (like https://my-shop.myshopify.com), the new country is permanently assigned as soon as I used it once as URL parameter.