Free shipping bar for Shopify Dawn that updates with the cart drawer (no app)

Disclosure: I build No-App Sections; this guide was written with AI assistance. Our ready-made section was tested on Dawn 16 (Shopify Theme Check, automated tests, and an unpublished Dawn theme on a Shopify development store). The snippets below are written for this guide. They pass Theme Check inside Dawn 16 and automated tests against mocked Shopify data, but they haven't been run on a live store, so try them on a duplicate theme first.

"You're £12.00 away from free shipping" is easy to render in Liquid. The hard part is keeping it right after the shopper changes the cart without reloading the page, which is what Dawn's cart drawer does. This is the developer deep dive: how Dawn actually updates its cart, and two ways to build a bar that keeps up.

If you only need a bar that's correct on page load, the shorter free shipping bar without an app guide is enough. This guide covers:

  1. A threshold that matches your shipping settings
  2. How Dawn actually updates its cart UI (from Dawn's source code, not guesswork)
  3. Option A: a zero-JavaScript bar inside Dawn's cart drawer
  4. Option B: a standalone section that updates anywhere on the page
  5. Currency formatting, Markets, and the gotchas that break most copy-paste versions

1. Pick the threshold

Go to Settings → Shipping and delivery and note the order value where free shipping starts, for example £50. The bar must match that exactly. Otherwise it promises something your checkout won't honour.

Liquid stores money as integers in the smallest unit. cart.total_price for £50.00 is 5000. Keep the threshold in the same unit and you'll never fight floating-point rounding.

2. How Dawn updates the cart (read the source first)

I went through Dawn 16.0.0's assets before writing any JavaScript. Two mechanisms matter.

Bundled section rendering. When you add to cart (product-form.js) or change a quantity (cart.js), Dawn posts to /cart/add or /cart/change with a sections parameter. Shopify then returns freshly rendered HTML for those sections in the same response. The cart drawer asks for the cart-drawer section and swaps in its .drawer__inner (or #CartDrawer after an add). The cart page asks for main-cart-items and main-cart-footer.

A tiny pub/sub. After each change, Dawn calls:

publish(PUB_SUB_EVENTS.cartUpdate, { source: 'product-form', cartData: response /* … */ });

publish, subscribe and PUB_SUB_EVENTS (cartUpdate: 'cart-update') are globals from assets/pubsub.js and assets/constants.js. subscribe() returns an unsubscribe function.

Dawn 16 also ships assets/standard-actions-override.js. When a cart change comes through Shopify's Standard Actions (Shopify.actions.updateCart), that file refreshes Dawn's cart sections and then publishes the same cart-update event. So subscribing to cart-update covers that route as well.

One thing that trips people up: Dawn doesn't dispatch a cart:updated DOM event. Searching Dawn's assets for cart:updated finds nothing. Some other themes and apps use that name, so it's worth listening for as a bonus, but on Dawn you have to use subscribe().

That gives us two clean ways to build the bar.

3. Option A: inside the cart drawer, zero JavaScript

Dawn already re-renders the whole .drawer__inner after every cart change. Put the bar inside it and Dawn keeps it up to date for you.

Step 1. In Online Store → Themes → … → Edit code, add a new snippet called free-shipping-bar.liquid:

{%- comment -%}
  Usage: {% render 'free-shipping-bar', threshold: 5000 %}
  threshold is in pence/cents (£50.00 = 5000), in your store currency.
{%- endcomment -%}
{%- liquid
  assign total = cart.total_price
  assign remaining = threshold | minus: total
  assign percent = 100
  if threshold > 0
    assign percent = total | times: 100 | divided_by: threshold | at_most: 100
  endif
-%}
<div class="free-ship-bar">
  <p class="free-ship-bar__msg">
    {%- if remaining > 0 -%}
      You're {{ remaining | money }} away from free shipping
    {%- else -%}
      You've unlocked free shipping!
    {%- endif -%}
  </p>
  <progress class="free-ship-bar__progress" value="{{ percent }}" max="100">{{ percent }}%</progress>
</div>
<style>
  .free-ship-bar { padding: 0 1.5rem 1rem; text-align: center; }
  .free-ship-bar__msg { margin: 0 0 .5rem; font-size: 1.4rem; }
  .free-ship-bar__progress { width: 100%; height: .8rem; }
</style>

Step 2. Open snippets/cart-drawer.liquid. Find the closing </div> of <div class="drawer__header">, just before <cart-drawer-items, and add:

{%- if cart != empty -%}
  {%- render 'free-shipping-bar', threshold: 5000 -%}
{%- endif -%}

cart is a global object, so it's available inside the rendered snippet. Only threshold has to be passed in.

That's it. Add a product: the drawer opens with the bar already filled. Change a quantity in the drawer: Dawn re-renders .drawer__inner and the bar comes with it. The same trick works on the cart page if you render the snippet inside the .js-contents element of sections/main-cart-footer.liquid, because Dawn re-renders that too.

The trade-offs: you've edited a theme file, so you'll need to redo it when you update Dawn. The threshold lives in code, and the bar only exists inside the drawer.

4. Option B: a standalone section that updates anywhere

If you want the bar in the header group (so it shows on every page), or you don't want to touch Dawn's files, make it a section. The section renders itself with Liquid on page load. When the cart changes, the script asks Shopify to re-render just this section through the Section Rendering API (?section_id=) and copies the new text and width into the page.

Why re-render the section rather than fetch /cart.js and rebuild the message in JavaScript?

  • The message stays in one place (the Liquid), so it can't drift between server and client.
  • Shopify's money filter does the currency formatting, so you don't need a JavaScript money formatter (more on that below).
  • Dawn itself uses the same pattern, so you're working with the theme rather than against it.

Create sections/free-shipping-bar.liquid:

{%- liquid
  # Threshold is entered in pounds/dollars; Liquid money values are in pence/cents.
  assign threshold = section.settings.threshold | times: 100 | round
  assign total = cart.total_price
  assign remaining = threshold | minus: total
  assign percent = 100
  if threshold > 0
    assign percent = total | times: 100 | divided_by: threshold | at_most: 100
  endif
  # Format the amount first, then drop it into the sentence.
  assign remaining_money = remaining | money
-%}
<div class="fsb" data-fsb>
  <p class="fsb__msg" id="FsbMsg-{{ section.id }}" data-fsb-msg aria-live="polite">
    {%- if remaining > 0 -%}
      {{ section.settings.msg_progress | replace: '[amount]', remaining_money }}
    {%- else -%}
      {{ section.settings.msg_done }}
    {%- endif -%}
  </p>
  <div
    class="fsb__track"
    role="progressbar"
    aria-labelledby="FsbMsg-{{ section.id }}"
    aria-valuemin="0"
    aria-valuemax="100"
    aria-valuenow="{{ percent }}"
    data-fsb-track
  >
    <div class="fsb__fill" data-fsb-fill style="width: {{ percent }}%"></div>
  </div>
</div>

<style>
  #shopify-section-{{ section.id }} .fsb { padding: 12px 16px; text-align: center; }
  #shopify-section-{{ section.id }} .fsb__msg { margin: 0 0 8px; font-size: 14px; }
  #shopify-section-{{ section.id }} .fsb__track {
    max-width: 480px; height: 8px; margin: 0 auto;
    background: rgba(0, 0, 0, .1); border-radius: 4px; overflow: hidden;
  }
  /* display: block matters: Dawn's base.css hides empty divs (div:empty { display: none }). */
  #shopify-section-{{ section.id }} .fsb__fill {
    display: block; height: 100%; background: #2e7d32; transition: width .4s ease;
  }
  @media (prefers-reduced-motion: reduce) {
    #shopify-section-{{ section.id }} .fsb__fill { transition: none; }
  }
</style>

<script>
  (function () {
    var sectionId = {{ section.id | json }};
    var timer = null;
    var latest = 0;
    var unsubscribe = null;

    // Ask Shopify to re-render just this section (Section Rendering API),
    // then copy the new text and width into the live DOM.
    function update() {
      var requestId = ++latest;
      var url = window.location.pathname + '?section_id=' + encodeURIComponent(sectionId);
      fetch(url, { headers: { Accept: 'text/html' } })
        .then(function (res) {
          if (!res.ok) throw new Error('Section render failed: ' + res.status);
          return res.text();
        })
        .then(function (html) {
          if (requestId !== latest) return; // a newer refresh is already on its way
          var fresh = new DOMParser()
            .parseFromString(html, 'text/html')
            .getElementById('shopify-section-' + sectionId);
          var current = document.getElementById('shopify-section-' + sectionId);
          if (!fresh || !current) return;

          var msg = current.querySelector('[data-fsb-msg]');
          var text = fresh.querySelector('[data-fsb-msg]').textContent;
          if (msg.textContent !== text) msg.textContent = text; // only announce real changes

          current.querySelector('[data-fsb-fill]').style.width =
            fresh.querySelector('[data-fsb-fill]').style.width;
          current.querySelector('[data-fsb-track]').setAttribute(
            'aria-valuenow',
            fresh.querySelector('[data-fsb-track]').getAttribute('aria-valuenow')
          );
        })
        .catch(function () {
          /* keep the last good value on screen */
        });
    }

    // Several cart events can arrive together; refresh once.
    function refresh() {
      clearTimeout(timer);
      timer = setTimeout(update, 50);
    }

    // Dawn: constants.js and pubsub.js load with `defer`, so they exist by DOMContentLoaded.
    function listenToDawn() {
      if (typeof subscribe === 'function' && typeof PUB_SUB_EVENTS !== 'undefined') {
        unsubscribe = subscribe(PUB_SUB_EVENTS.cartUpdate, refresh);
      }
    }
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', listenToDawn);
    } else {
      listenToDawn(); // theme editor re-render: the page is already loaded
    }

    // Other themes and apps: many dispatch a `cart:updated` DOM event. Dawn doesn't.
    document.addEventListener('cart:updated', refresh);

    // Back/forward cache: the cart may have changed on another page.
    window.addEventListener('pageshow', function (e) {
      if (e.persisted) refresh();
    });

    // Theme editor: clean up when this section is removed or re-rendered.
    document.addEventListener('shopify:section:unload', function onUnload(e) {
      if (!e.detail || e.detail.sectionId !== sectionId) return;
      if (unsubscribe) unsubscribe();
      clearTimeout(timer);
      document.removeEventListener('cart:updated', refresh);
      document.removeEventListener('shopify:section:unload', onUnload);
    });
  })();
</script>

{% schema %}
{
  "name": "Free shipping bar",
  "tag": "section",
  "class": "section-free-shipping-bar",
  "settings": [
    {
      "type": "number",
      "id": "threshold",
      "label": "Free shipping threshold (store currency)",
      "info": "Must match Settings > Shipping and delivery",
      "default": 50
    },
    {
      "type": "text",
      "id": "msg_progress",
      "label": "Message below the threshold",
      "info": "[amount] is replaced with the amount left",
      "default": "You're [amount] away from free shipping"
    },
    {
      "type": "text",
      "id": "msg_done",
      "label": "Message once reached",
      "default": "You've unlocked free shipping!"
    }
  ],
  "presets": [{ "name": "Free shipping bar" }]
}
{% endschema %}

Then go to Customize, click Add section in the header (or on the cart template), pick Free shipping bar, set the threshold, and save.

What each part of the script is doing

  • window.location.pathname + '?section_id=…': the Section Rendering API returns the section's HTML wrapped in <div id="shopify-section-{id}">. Requesting it on the current path keeps the right Liquid context and language/market prefix, which is also what Dawn does (it sends sections_url: window.location.pathname). Sections in JSON templates or section groups have dynamic IDs such as sections--1234__free_shipping_bar. section.id gives you the right one.
  • subscribe(PUB_SUB_EVENTS.cartUpdate, refresh): Dawn's own cart event. Dawn loads constants.js and pubsub.js with defer, and our inline script runs before deferred scripts. If you call subscribe straight away, you'll get subscribe is not defined. Deferred scripts run before DOMContentLoaded, so we wait for that.
  • cart:updated: a bonus for other themes and apps that dispatch it. It's harmless on Dawn.
  • Debounce + latest counter: several events can fire for one change, and responses can come back out of order. We refresh once, and we ignore a stale response.
  • Copy text and width instead of swapping innerHTML: the message is an aria-live="polite" region. Replacing the element would stop screen readers announcing the change reliably, so we update its text, and only when it actually changed.
  • shopify:section:unload: the theme editor re-runs a section's script every time you change a setting. Without cleanup, every edit adds another subscriber and one cart change sets off several requests.

5. Currency formatting (and the Markets catch)

On the server, money formats the amount using your store's money format and the shopper's presentment currency. One subtle bug to avoid: put the money filter on the number, before it goes into the sentence:

{%- comment -%} Wrong: money is applied to the whole sentence {%- endcomment -%}
{{ section.settings.msg_progress | replace: '[amount]', remaining | money }}

{%- comment -%} Right: format first, then substitute {%- endcomment -%}
{%- assign remaining_money = remaining | money -%}
{{ section.settings.msg_progress | replace: '[amount]', remaining_money }}

Liquid filters run left to right, so in the first version money receives the output of replace, which is the whole sentence. We hit exactly this bug in our own section during testing.

Store money formats can contain HTML entities, for example &pound;{{amount}}. Option B reads the fresh message with textContent from the parsed response, so the browser decodes the entity and shoppers see £, not &pound;.

In the browser, if you go the /cart.js route instead, note that Dawn doesn't include the old Shopify.formatMoney helper. Code that calls it will throw. A dependency-free fallback:

function formatMoney(cents, currency) {
  return new Intl.NumberFormat(document.documentElement.lang || undefined, {
    style: 'currency',
    currency: currency
  }).format(cents / 100);
}

fetch(window.Shopify.routes.root + 'cart.js')
  .then(function (res) { return res.json(); })
  .then(function (cart) {
    console.log(formatMoney(Math.max(0, 5000 - cart.total_price), cart.currency));
  });

Intl won't always match your store's own money format exactly (decimals, symbol placement, a trailing "GBP"). That's another reason Option B lets Liquid do the formatting.

Shopify Markets: cart.total_price is in the shopper's currency, but your threshold is in your store currency. If you sell in several currencies, either set the threshold per market, or convert it in JavaScript with Shopify.currency.rate (which is what our section does). Also check that each market's free-shipping rate in Shipping settings matches what the bar promises.

6. Gotchas we hit while testing

  • Dawn hides empty divs. Dawn's base.css has div:empty { display: none }. A progress fill <div> with no children counts as empty, so on Dawn you'd see a grey track and no fill, even at 100%. The display: block on .fsb__fill fixes it. (Option A uses <progress>, which isn't affected.)
  • Decimal thresholds. 49.99 | times: 100 isn't guaranteed to be exactly 4999, so | round it.
  • Integer division. divided_by with an integer divisor rounds down in Liquid. That's what we want for a percentage, and it's why we multiply by 100 first.
  • Cap the percentage. | at_most: 100, or a £120 cart shows a 240% bar.
  • Carts changed by other code. If an app changes the cart without going through Dawn's product form or cart code, Dawn's pub/sub won't fire. If the app dispatches cart:updated, Option B still catches it. If not, the bar corrects itself on the next page load.

Testing checklist

On a duplicate of your theme, with the cart drawer turned on (Theme settings → Cart → Cart type: Drawer):

  1. Empty cart: "£50.00 away", 0% fill.
  2. Add a product from the product page: the bar updates without a reload.
  3. Change a quantity in the drawer, then remove an item: the bar updates each time.
  4. Cross the threshold: "unlocked", 100% fill.
  5. Change a setting in the theme editor several times, then add to cart: one request in the Network tab, not several.
  6. Open DevTools: no console errors.

Or skip the code: a free ready-made section

If you'd rather not maintain this yourself, I've packaged a free free-shipping bar section. It's one Liquid file you paste in once and then set up in the theme editor (threshold, messages and colours). It uses your store's money format, converts the threshold for Shopify Markets currencies (tested with mocked data; not yet on a live multi-currency store), and refreshes after the theme's AJAX cart changes. It's tested on Dawn and Horizon. Other Online Store 2.0 themes may need small style tweaks. You get it by entering your email on a short form.

Get the free section Try the live demo

Everything above works without it, though. If you build your own, I'd like to hear which approach you went with: email thomas-ventures+support@mail.grokbot.com.

FAQ

Should I use Option A or Option B?

Option A if you only want the bar inside Dawn's cart drawer and don't mind editing a theme file. Option B if you want it in the header group or on any template, with the threshold and messages in the theme editor, and without touching Dawn's own files.

Does this work in themes other than Dawn?

Option A relies on Dawn re-rendering .drawer__inner, so it's Dawn-specific. Option B also listens for the cart:updated event that some other themes and apps dispatch; if a theme sends neither, the bar corrects itself on the next page load.