Back to Shopify Liquid
Free Shipping Nationwide
Shopify Liquid

Free Shipping Nationwide

Displays a dynamic shipping box that detects the visitor's country via IP and calculates an estimated delivery window based on the current date. It uses external geolocation to personalize the free shipping message and improve conversion through localized urgency.

MediumShippingTrustCRO尊Product Page贯Localization
45 lines · 2.7 KB
Setup 15–25 minutes 5 min read 44 lines
Key features
  • IP-based country detection
  • Dynamic delivery date calculation
  • Localized Spanish messaging
  • External JSON API integration
  • Visual shipping UI badge
Best use cases
  • Displaying localized free shipping offers on product pages.
  • Providing automatic delivery time estimates to international customers.
  • Increasing buyer confidence with visual shipping indicators.
Compatibility
  • Most Shopify themes

The code

Shopify Liquid
1<!--INICIO CÓDIGO ENVIO GRATIS-->
2<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
3
4<script>
5
6 function convertDate(e) {
7 var t, o = new Date(e);
8 return [(t = o.getDate(), t < 10 ? "0" + t : t)].join("/")
9 }
10
11 function getMesExtenso(e) {
12 var t = new Array(12);
13 return t[0] = "Ene", t[1] = "Feb", t[2] = "Mar", t[3] = "Abr", t[4] = "May", t[5] = "Jun", t[6] = "Jul", t[7] = "Ago", t[8] = "Sep", t[9] = "Oct", t[10] = "Nov", t[11] = "Dic", t[e]
14 }
15 jQuery(document).ready(function(e) {
16 var t = new Date,
17 o = t.setDate(t.getDate() + 5),
18 n = t.setDate(t.getDate() - 4),
19 r = getMesExtenso(t.getMonth());
20 if (convertDate(o) > convertDate(n)) var a = "<strong>" + convertDate(n) + "</strong> y el <strong>" + convertDate(o) + " de " + r + "</strong>";
21 else {
22 if (null == (s = getMesExtenso(t.getMonth() + 1))) var s = getMesExtenso(t.getMonth() - 11);
23 a = "<strong>" + convertDate(n) + " de " + r + "</strong> y <strong>" + convertDate(o) + " de " + s + "</strong>"
24 }
25 e.getJSON("https://ipapi.co/json/", function(t) {
26 var country = t.country_name;
27 e(".custom-address").html("<font color='#027548'><b>Envío gratis</b></font> a todo <strong><font color='#027548'>" + country + "</font></strong>"), e(".shipping-estimated").html("Recibe tu producto entre el: " + a + "."), e(".shipping-preview-loading").hide()
28 })
29 });
30
31</script>
32
33<div class="shipping-preview-line" style="position: relative; background: #F5F5F5; border: 1px solid #E5E5E5; border-bottom: 4px solid #ccc; border-radius: 8px; margin-top: 10px; margin-left: 0px; margin-bottom: 10px; margin-right: 0px; padding-top: 22px; padding-left:0px; padding-bottom:7px; padding-right:15px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.5);display: inline-block;">
34
35 <img style="height: 30px;width: 42px;position: absolute; left:3px; top: 10px;" src="https://cdn.shopify.com/s/files/1/0867/2696/7618/files/envio-gratis-2.svg?v=1712773120" class="shipping-country-flag fadeIn lazyloaded " alt="brazil">
36
37 <p class="shipping-preview-loading" style="text-align: left !important;color: #4a4a4a !important;padding: 0 0 0 50px;font-size: 12px !important;margin: -15px 0 30px -7px;display:block;">Cargando, espere...</p>
38
39 <p style="text-align: left !important;color: #4a4a4a !important;padding: 0 0 0 50px;font-size: 12px !important;margin: -15px 0 0 -7px;" class="custom-address"></p>
40
41 <p style="margin:-0.9px;text-align: left !important;color: #4a4a4a !important;padding: 0 0 0 50px;font-size: 11px !important;margin: -6px 0 0 -7px;" class="shipping-estimated"></p>
42
43</div>
44<!--FINAL CÓDIGO ENVIO GRATIS-->

How to install Free Shipping Nationwide on your Shopify theme

This snippet belongs in sections/main-product.liquid, directly under the Add to cart button, where it reinforces the purchase decision. Expect the whole job to take about 15–25 minutes.

  1. 1From your Shopify admin, open Online Store → Themes, click the button on your live theme and choose Duplicate. Always work on a copy so you can roll back instantly.
  2. 2On the duplicated theme, click … → Edit code to open the theme code editor.
  3. 3Open sections/main-product.liquid in the file tree. If your theme uses different file names, search for the template that renders the area where you want the block to show up.
  4. 4Click Copy code on this page, then paste the snippet directly under the Add to cart button, where it reinforces the purchase decision.
  5. 5Keep the <script> tag at the end of the snippet. It only runs once the surrounding markup exists in the DOM, so moving it higher up the file can break the behaviour.
  6. 6Click Save, then hit Preview and check the block on desktop, tablet and mobile widths.
  7. 7When you are happy with the result, publish the duplicated theme from Online Store → Themes → Actions → Publish.

How to customise it

Every value below lives inside the snippet, so you can adapt Free Shipping Nationwide to your brand without touching the rest of the theme.

  • Colours — the snippet uses #027548, #F5F5F5, #E5E5E5, #ccc. Replace those values inside the style block with your brand palette, keeping at least a 4.5:1 contrast ratio between text and background so the block stays accessible.
  • Sizing — adjust the font-size values (12px !important, 11px !important) and the padding so the block carries the same visual weight as the elements around it.
  • Cornersborder-radius: 8px controls the roundness. Set it to 0 for a sharper editorial look, or increase it for a softer, app-like feel.
  • Images — replace the placeholder image URLs with your own assets. Upload them under Content → Files in Shopify admin and use the generated CDN URL, or reference a theme asset with {{ 'my-image.png' | asset_url }}.
  • Copy — rewrite the hard-coded text (for example “convertDate(n)) var a = "”) in your own brand voice, and translate it if you sell in more than one language.

Common mistakes to avoid

These are the issues merchants run into most often when installing a snippet like this one.

  • Editing the live theme directly. Duplicate it first — a single unbalanced Liquid tag can take a storefront down mid-campaign.
  • Pasting the code into the wrong file. Dropped into layout/theme.liquid instead of sections/main-product.liquid, this block will render on every page of the store, including ones where it makes no sense.
  • Adding the snippet twice on the same page. The script targets its selector, so two copies can conflict or double-fire.
  • Leaving the demo images in place. They are hosted on third-party domains, can disappear at any time and slow the page down. Re-upload them to Shopify Files before going live.
  • Publishing without testing on a real phone. Most Shopify traffic is mobile, and layout problems almost always surface there first.

Performance notes

What this block costs you in load time, and how to keep that cost at zero.

  • The JavaScript is vanilla — no jQuery, no external library, no additional request. Keep it after the markup so it never blocks rendering.
  • Add loading="lazy" plus explicit width and height attributes to every image in the snippet. That prevents Cumulative Layout Shift, which is a Core Web Vitals ranking factor.
  • Third-party image URLs bypass the Shopify CDN and add extra DNS lookups. Self-hosting those assets usually saves 100–300ms on first paint.
  • Run PageSpeed Insights before and after you add the block so you have a concrete number rather than a guess.

SEO & accessibility

How to add this block without damaging your on-page structure or your rich results.

  • Nothing in this snippet should replace your page <h1>. Keep product and page headings intact and use <h2> or <h3> for the block's own heading so the document outline stays clean.
  • Write a descriptive alt attribute for every image. Empty or generic alt text is one of the most common accessibility and SEO issues on Shopify stores.
  • If the block shows review or rating content, keep it consistent with the structured data your review app already outputs. Duplicating or contradicting rating markup can cost you the rich result entirely.
  • The block does not create a new URL, so there is no canonical or indexing change to make. It improves on-page engagement signals rather than crawlability.
Frequently asked questions

Free Shipping Nationwide — questions merchants ask

Will this snippet work with my theme?

It is built with standard Liquid, HTML and CSS, so it works with Dawn and virtually every Online Store 2.0 theme, as well as most vintage themes. The only thing that changes between themes is the file you paste it into — if yours has no sections/main-product.liquid, look for the equivalent template that renders the same area.

Do I need an app to use it?

No. This is theme code you own outright: no monthly fee, no third-party script tag, and no app that can break your storefront the next time it updates.

How long does it take to add “Free Shipping Nationwide” to a store?

Most merchants have it live in under fifteen minutes — duplicate the theme, paste the code, adjust the colours and copy, preview on mobile, publish.

The block appears but nothing happens. What is wrong?

That is almost always a script-order problem. Check that the script tag is still at the bottom of the snippet and that the markup was not pasted inside another script or a Liquid comment block. Open your browser console and look for an error naming the snippet's selector.

Will it slow my store down?

Not meaningfully. It is inline markup with scoped CSS and at most a few lines of vanilla JavaScript — no external libraries, no extra HTTP request. Optimising your product images will always have a far bigger impact on load time.

Can I use it on a client store or a commercial project?

Yes. Every snippet in the MCO Hub library is free to copy, modify and ship on any store, including client work. Attribution is appreciated but not required.

Related snippets

Keep exploring