Delivery lead time widget

Hi im trying to make a simple widget where it would say “Delivery to (Country_flag) in 2 days” where Country_Flag would be dynamic field detecting visitors geo location and would return the country flag.

Currently i made a delivery-time-js.liquid snippet with code:

{% assign country_code = localization.country.iso_code | default: “XX” %}

{% case country_code %}{% when “US” %} {% assign country_flag = “🇺🇸” %}{% when “DE” %} {% assign country_flag = “🇩🇪” %}{% when “FR” %} {% assign country_flag = “🇫🇷” %}{% when “GB” %} {% assign country_flag = “🇬🇧” %}{% when “CA” %} {% assign country_flag = “🇨🇦” %}{% when “LT” %} {% assign country_flag = “🇱🇹” %}{% else %} {% assign country_flag = “🌍” %}{% endcase %}


And then i add a custom liquid section to my theme editor with {% render ‘delivery-time-js’ %}.

The issue that I have is that the country_flag renders country initials but not the flag icon

Example United Kingdom:

Could anyone help me out with this? Much appreciated.

Hi, how did you render the “Delivery to GB by 10.10” text? (full code)

You can try to use this code then check

<div class="delivery-widget" style="display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 14px; margin: 10px 0;">
  Delivery to <strong><img style="width: 20px;"
    src="{{ flag_url }}" 
    width="20" 
    height="15" 
    alt="{{ localization.country.name }}"
    style="object-fit: contain; border-radius: 2px; box-shadow: 0 1px 2px rgba(0,0,0,0.1);"
  ></strong> in 2 days
</div>

Best regards,

Dan from Ryviu: Product Reviews App

Shopify has built-in functionality to show flags –

Horizon uses it like this:

1 Like

Using this updated code the flag icon is now working, but isn’t it true, that localization.country takes the store’s country and returns the flag for that? Not customer’s actual IP adress country?

{% assign country_code = localization.country.iso_code | default: “XX” %}

{% assign country_flag = localization.country | image_url: width: 20 %}

Delivery to

{% if country_code != “XX” %}

<img src="{{ country_flag }}" alt="{{ localization.country.name }} flag" style="vertical-align: middle; width: 20px; height: 15px;" />

{{ localization.country.name }}

{% else %}

🌍 Worldwide

{% endif %}

by 10.10

I connected to VPN and selected United Kingdom as country, but the widget is still showing my original location(Lithuania)

Here is the preview link: https://a2w1n5vaa3oo6sxb-77830390093.shopifypreview.com

Yes, localization does not show the actual customer region, but rather what they’ve selected in country/language menu.

What I’d consider:

  1. Automatic country redirect – https://help.shopify.com/en/manual/international/automatic-redirection to make current localization country match actual visitors country;
  2. Shopify has Browsing context suggestions API to detect visitors actual location – you can use that – Detect and set a visitor’s optimal localization

If I to implement this, I’d output messages for each country with liquid with style="display:none", then use API from #2 to remove style attribute from one of these based on result.

Something like:

{% for c in localization.available_countries %}
  <span data-country="{{ c.iso_code }}" style="display: none"> 
    Delivery to {{c.iso_code }} is XXX days 
  </span>
{% endfor %}

<script>
  fetch('/browsing_context_suggestions.json')
    .then(r => r.json())
    .then(r => r?.detected_values?.country?.handle)
    .then(country => {
      if (!country) return;
      document.querySelector('[data-country="' + country + '"]')?.removeAttribute('style'); 
    });
</script>
1 Like

Actually i just cleaned my cookies and the previous code works OK to display country flag based on my VPN location.

Regarding your /1 comment, the automatic redirection does not work in the EU. So French who visit .de page are not automatically redirected to .fr

Now that after cleaning cookies my initial approach works ok, is there any benefit to update with your method?

Full code of my approach:

{% assign country_code = localization.country.iso_code | default: "XX" %}
{% assign country_flag = localization.country | image_url: width: 20 %}

{% if country_code == "LT" %}
  {% assign delivery_days = 2 %}
{% else %}
  {% assign delivery_days = 5 %}
{% endif %}

{% assign full_text = "liquid_deliveryLabel.delivery_to" | t %}
{% assign warranty_translated = "liquid_deliveryLabel.warranty" | t %}
{% assign days_text = "liquid_deliveryLabel.days" | t %}
{% assign in_text = "liquid_deliveryLabel.in" | t %}

{% assign warranty_bold = "<strong>" | append: warranty_translated | append: "</strong>" %}

{% assign bolded_text = full_text | replace: "{{warranty}}", warranty_bold %}

<div id="delivery-label" class="delivery-badge">
  {{ bolded_text | raw }}
  {% if country_code != "XX" %}
    <img src="{{ country_flag }}" alt="Country flag" style="vertical-align: middle; width: 18px; height: 15px;" />
  {% else %}
    🌍
  {% endif %}
  {{ in_text }} <strong>{{ delivery_days }} {{ days_text }}</strong>
</div>

Oh, of course EU has some quirks.

However looks like it’s about keeping TLD, not subfolders like /en-us/ or /fr-fr/?
Sure depends on your setup.

Then it depends no more testing results.

I’d say that Browsing context suggestions will give your “non-politicized” lower level info while localization should give your visitor a chance to manually select the delivery country.
:slight_smile:

You misunderstand the purpose of this widget. This purely should act as a simple trust badge. Its informational only :slight_smile:

1 Like

IP geolocation is inherently imprecise. VPN users, corporate networks, mobile carriers that route through centralised servers, and shared ISP infrastructure all produce false location signals. VPNs are increasingly mainstream, not just a technical tool. A significant portion of ordinary consumers use them routinely, and their apparent location bears no relation to where they actually are.

Mobile networks compound this. Carrier-level NAT and traffic routing means mobile users often appear to be wherever their carrier’s gateway is, or where the traffic has been load-balanced to - which can be in a different country - especially in Europe. I’m in the UK and have been load-balanced to the Netherlands before.

The browser Geolocation API has always required explicit user permission, but what has changed is how aggressively browsers default to blocking or obscuring it. Firefox has offered resistance fingerprinting modes for years, and its stricter privacy settings return deliberately imprecise coordinates even when permission is granted. Safari on iOS uses a similar approach, rounding coordinates to reduce precision. Brave blocks geolocation by default and requires manual override per site.

Chrome is the outlier in being relatively permissive, but even Chrome has moved toward blocking geolocation on pages loaded over HTTP and prompting more assertively when a site requests it.

So what is your solution then?