button link to different page based on user's country

Silax
Shopify Partner
19 0 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?

 

Replies 2 (2)

DigiDecoded
Shopify Partner
158 19 18

@Silax wrote:

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

 

Danish | Full Stack Developer @ Esire.Inc
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- Hire me for your next task! | Email | WhatsApp | Website

Xipirons
Shopify Partner
136 24 30

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">www.linkA.com</a>
{% elsif localization.country.iso_code == 'FR' %}
  <a href="www.linkB.com">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.

Was this helpful? Like or Accept solution - Buy me a coffee
- Contact me: Xipirons | WhatsApp
- Shopify Developer based in France, helping online merchants succeed