Button link to different page based on user's country

Topic summary

Goal: Make a single button link to different URLs based on the visitor’s country (e.g., US → linkA, UK → linkB).

Proposed approaches:

  • Approach 1: Use the X-Shopify-Time zone HTTP header in Liquid to infer region (e.g., contains ‘America’ or ‘Europe’) and conditionally set values, then map to links.
  • Approach 2: Use Shopify’s built-in localization.country.iso_code (country ISO code) in Liquid (Shopify’s templating language) to render different links per country, with a default fallback.

Implementation notes (Approach 2):

  • Place conditional Liquid in theme .liquid files (sections, product descriptions, banners, navigation, etc.).
  • No JavaScript or third-party apps required. Test behavior via a VPN simulating different countries.

Limitations mentioned:

  • Manual maintenance of Liquid conditions.
  • Country-level targeting only (no finer regional granularity).
  • No automatic redirects; it conditionally displays content.

Status: Guidance and example code were provided; the original poster has not confirmed a solution. Code snippets are central to understanding the proposed methods.

Summarized with AI on January 1. AI used: gpt-5.

Scenario: The same button is clicked, User A from US, User B from UK.

User A when clicked direct to www.linkA.com

User B when clicked direct to www.linkB.com

How can i achieve this?

{% assign user_timezone = request.http_headers.X-Shopify-Timezone %}
{% if user_timezone contains 'America' %}
  {% assign currency_code = 'USD' %}
{% elsif user_timezone contains 'Europe' %}
  {% assign currency_code = 'EUR' %}
{% else %}
  {% assign currency_code = 'GBP' %}
{% endif %}

try this logic and modify the code accordingly, placed the link in places of usd and euro

Hi @Silax

Here’s how you can display different content on your Shopify site based on the user’s geographic location, without using any third-party apps:

  1. Get the user’s country code using Shopify’s built-in Liquid object localization.country.iso_code. This does not require an app.
  2. Then use Liquid conditionals to show different content based on the country code. For example:
{% if localization.country.iso_code == 'US' %}
  <a href="[www.linkA.com](http://www.linkA.com)">[www.linkA.com](http://www.linkA.com)</a>
{% elsif localization.country.iso_code == 'FR' %}
  <a href="[www.linkB.com](http://www.linkB.com)">[www.linkB.com](http://www.linkB.com)</a>
{% else %}
  <p>Default content for other countries</p>  
{% endif %}

This will display:

  • The button “www.linkA.com” if the country code is US
  • The button “www.linkB.com” if the country code is FR
  • The “Default content” paragraph for all other countries

You can apply this conditional logic to any element in your Shopify theme:

  • Static content sections and blocks
  • Product descriptions
  • Banners and announcement bars
  • Navigation links
  • etc…
  1. Simply insert the Liquid code in the appropriate places in your theme’s .liquid files. No need to modify any JavaScript files.
  2. Test using a VPN to simulate connecting from different countries and verify the correct content shows up.

This approach has some limitations compared to using a dedicated app:

  • You have to maintain the Liquid code yourself in your theme
  • You can’t target regions more specific than country
  • You don’t get advanced features like automatic redirects

But for simple needs of customizing content per country, using localization.country.iso_code with Liquid conditionals is a lightweight, free solution that doesn’t require a third-party app on your Shopify store.