Country switcher stops working when ?country= is present in URL

Ran into an issue with Shopify localization:

When navigating from the new customer account page back to the homepage, Shopify appends ?country= to the URL.
After that, the country switcher (using {% form 'localization' %}) stops functioning properly.

Repro steps:

  1. Go to customer account page

  2. Click “Home”

  3. URL becomes something like /?country=XX

  4. Try switching country → :cross_mark: no effect

Code:

 {%- form 'localization' -%}
      ....
 <input type="hidden" name="country_code" value="{{localization.country.iso_code }}">
 {%- endform -%}

i use js to update the country_code when selecting country

I also tried just basic and its not working

  {% form 'localization' %}
      <input type="text" name="language_code" value="en">
      <input type="text" name="country_code" value="us">
      <button type="submit">ENTER</button>
 {% endform %}

  • Switcher works when removing ?country parameter

Suspected cause:
The ?country query param seems to override or interfere with Shopify’s localization form submission.

Hey again @0_0 - thanks for flagging this. Happy to dig into this more on our end. Just a few questions here to narrow things down:

  1. When you try to switch countries with the ?country= parameter in the URL, what exactly happens? Does the page reload and stay on the same country, or does nothing happen at all?
  2. What theme are you using? Custom build or a Shopify theme like Dawn/Horizon?

Also just to confirm, the code snippet you shared is a minimal repro? I’m assuming your full country switcher has a way for customers to actually select a different country before the form submits. I’ll try to replicate things on my end here once I hear back from you so we can get this looked into.

Hope to hear from you soon!

  1. Page Reloads but nothing happens, I think it the country params is being prioritized

  2. Custom build theme

    Yes but after testing with the most minimal code it still doesnt work so im assuming its a bug.

Hey @0_0 - thanks for confirming all that, really helpful.

So based on what you’re describing, this looks like the ?country= parameter in the URL is likely overriding whatever the localization form tries to set. What I think might be happening is: when the localization form submits, it sends the new country_code to /localization and includes a return_to value based on the current page URL. If that URL still has ?country=XX in it, the redirect back to that URL could be forcing the localization right back to the original country, which would explain why the page reloads but nothing changes.

As a workaround, you could try stripping the ?country= parameter from the URL via JavaScript when the page loads. Something like this:

if (window.location.search.includes('country=')) {
  const url = new URL(window.location.href);
  url.searchParams.delete('country');
  window.history.replaceState({}, '', url.toString());
}

That should clean up the URL without triggering a page reload, and then your country switcher form should work as expected after that.

Could you give that a try and let me know if it resolves things on your end? I can also look into this internally to confirm if this is expected behaviour.

Thanks Alan,

Removing the parameter works,
but it doesn’t fix the root cause, changing it might introduce other bugs so i understand

For now, I’ll remove the country parameter as a workaround.

Hey @0_0 - glad that’s working for now. I hear you on the root cause though. I’ve flagged this internally on our end so the team is aware of the ?country= parameter interfering with the localization form. Let me know if anything else pops up in the meantime!

Hey @0_0 - closing the look here. I was able to confirm internally that the initial issue you reported is something on our end and we have a bug investigation logged for it. I can’t guarantee a turnaround time on a fix, but I did want to let you know we’re looking into it on our side.