All guides › Sticky add to cart with delivery

Sticky add to cart for Dawn, with your delivery line underneath, no app

Disclosure: I build No-App Sections; this guide was written with AI assistance. The code on this page was written for this guide. It passes Shopify's Theme Check inside Dawn 16.0.0 and automated tests in headless Chrome, run against Dawn's own cart and variant events with mocked store data. It hasn't been run on a live store yet, so try it on a duplicate theme first.

On a phone, Dawn's Add to cart button scrolls away as soon as someone starts reading the description. A sticky bar brings it back. Most sticky bar apps build a second, separate add-to-cart form, which is where the bugs come from: the wrong variant, quantity ignored, the cart drawer not opening. This one doesn't add anything to the cart itself. It presses Dawn's own button, and copies the price, the button text and your delivery line from the page.

What the bar shows, and where each part comes from

In the barCopied fromUpdates when
Product titleLiquid, onceNever needs to
PriceDawn's .price-item--last (the current price)The shopper picks another variant
Button text and disabled stateDawn's [name="add"] buttonSold out / Unavailable / Add to cart changes
Delivery lineThe first element matching delivery_selectorEvery time that text changes, including a ticking countdown

Because everything is copied, there's nothing to keep in sync by hand. If the main button says "Sold out" and is disabled, so is the bar's. If there's no delivery line on the page, that row of the bar is simply hidden.

Why it presses the real button

Dawn's add-to-cart form handles the selected variant, the quantity box, line item properties, error messages ("You can't add more of this item") and opening the cart drawer or notification. A tap on the bar runs mainButton.click(), so all of that keeps working, and anything you or an app has added to the form keeps working too.

The block

{%- comment -%}
  Sticky add-to-cart bar for phones that carries your delivery line with it.
  Add as a "Custom Liquid" block anywhere in Product information (Dawn 16).
  The bar never adds to cart itself: it presses Dawn's real button, so variants, quantity,
  the cart drawer and error messages all keep working exactly as before.
  delivery_selector: the element whose text should be copied into the bar (first match wins).
{%- endcomment -%}
{%- liquid
  assign delivery_selector = '.delivery-countdown__main, .fdd__main, .dispatch-time'
  assign phone_only = true
-%}
<sticky-atc
  class="sticky-atc{% if phone_only %} sticky-atc--phone{% endif %}"
  data-section="{{ section.id }}"
  data-delivery="{{ delivery_selector | escape }}"
  hidden
>
  <div class="sticky-atc__row">
    <div class="sticky-atc__info">
      <p class="sticky-atc__title">{{ product.title | escape }}</p>
      <p class="sticky-atc__price"></p>
    </div>
    <button type="button" class="sticky-atc__button button button--primary">Add to cart</button>
  </div>
  <p class="sticky-atc__delivery" hidden></p>
</sticky-atc>
<style>
  .sticky-atc { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; padding: 0.8rem 1.5rem calc(0.8rem + env(safe-area-inset-bottom)); background: rgb(var(--color-background)); box-shadow: 0 -0.2rem 1rem rgba(0, 0, 0, 0.12); }
  .sticky-atc[hidden] { display: none; }
  .sticky-atc__row { display: flex; align-items: center; gap: 1rem; }
  .sticky-atc__info { flex: 1; min-width: 0; }
  .sticky-atc__info p, .sticky-atc__delivery { margin: 0; }
  .sticky-atc__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.3rem; }
  .sticky-atc__price { font-weight: 600; }
  .sticky-atc__button { min-width: 0; padding: 0 1.6rem; white-space: nowrap; }
  .sticky-atc__delivery { margin-top: 0.4rem; font-size: 1.2rem; }
  body.has-sticky-atc { padding-bottom: 9rem; }
  @media screen and (min-width: 750px) {
    .sticky-atc--phone { display: none !important; }
    body.has-sticky-atc { padding-bottom: 0; }
  }
</style>
<script>
  if (!customElements.get('sticky-atc')) {
    customElements.define('sticky-atc', class extends HTMLElement {
      connectedCallback() {
        const id = this.dataset.section;
        this.form = document.getElementById('product-form-' + id);
        this.mainButton = this.form && this.form.querySelector('[name="add"]');
        if (!this.mainButton || !('IntersectionObserver' in window)) return;
        this.priceBox = document.getElementById('price-' + id);
        this.button = this.querySelector('.sticky-atc__button');
        this.button.addEventListener('click', () => {
          if (!this.mainButton.disabled) this.mainButton.click();
        });
        this.io = new IntersectionObserver(([entry]) => {
          const show = !entry.isIntersecting && entry.boundingClientRect.top < 0;
          this.hidden = !show;
          document.body.classList.toggle('has-sticky-atc', show);
        });
        this.io.observe(this.mainButton);
        /* Dawn rewrites the price, button and delivery text on variant change; copy whatever it shows. */
        this.mo = new MutationObserver((records) => {
          if (records.some((r) => !this.contains(r.target))) this.sync();
        });
        const root = document.getElementById('MainProduct-' + id) || document.body;
        this.mo.observe(root, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ['disabled', 'hidden', 'class'] });
        this.sync();
      }
      disconnectedCallback() {
        if (this.io) this.io.disconnect();
        if (this.mo) this.mo.disconnect();
        if (this.sourceMo) this.sourceMo.disconnect();
        document.body.classList.remove('has-sticky-atc');
      }
      sync() {
        const set = (el, value) => { if (el.textContent !== value) el.textContent = value; };
        const label = this.mainButton.querySelector('span') || this.mainButton;
        set(this.button, label.textContent.trim());
        const disabled = this.mainButton.disabled;
        if (this.button.disabled !== disabled) this.button.disabled = disabled;
        const price = this.priceBox && this.priceBox.querySelector('.price-item--last');
        set(this.querySelector('.sticky-atc__price'), price ? price.textContent.trim() : '');
        const line = this.querySelector('.sticky-atc__delivery');
        const source = [...document.querySelectorAll(this.dataset.delivery)].find((el) => !this.contains(el) && !el.closest('[hidden]') && el.textContent.trim());
        /* The delivery line may live in another section (and tick every few seconds): watch it directly. */
        if (source && source !== this.watched) {
          if (this.sourceMo) this.sourceMo.disconnect();
          this.sourceMo = new MutationObserver(() => this.sync());
          this.sourceMo.observe(source.parentNode || source, { subtree: true, childList: true, characterData: true });
          this.watched = source;
        }
        const text = source ? source.textContent.replace(/\s+/g, ' ').trim() : '';
        set(line, text);
        if (line.hidden !== !text) line.hidden = !text;
      }
    });
  }
</script>

Install it

  1. Open the product template. Go to Online Store → Themes → Customize and choose Products → Default product.
  2. Add a Custom Liquid block. In Product information, add a Custom Liquid block. Where it goes doesn't matter, because the bar is fixed to the bottom of the screen. The end of the list is tidy.
  3. Paste the code. Paste the block from above. Change delivery_selector if your delivery text uses another class.
  4. Check your colours. The bar's background is Dawn's --color-background and the button is Dawn's primary button, so it follows your colour scheme. If it looks wrong, change the background in the first .sticky-atc rule.
  5. Save and test on a real phone. The theme editor preview is narrow but isn't a phone. Use your phone or the browser's device toolbar, and go through the checklist below.

When it appears

An IntersectionObserver watches Dawn's Add to cart button. The bar slides in only when that button has scrolled above the screen, so it never sits on top of the real button, and it doesn't show on page load. While the bar is visible, the page gets a little bottom padding (the has-sticky-atc class) so the footer isn't hidden behind it.

phone_only hides it from 750px wide upwards, Dawn's tablet breakpoint. On desktop, Dawn already has a built-in option: in the product section, turn on Enable sticky content on desktop and the whole product information column (price, buttons and your delivery block) stays in view while the shopper scrolls the images. That's usually better than a bar on a large screen. Set phone_only to false only if you have a reason.

Pointing it at your delivery line

delivery_selector is a list of CSS selectors, and the first one found on the page wins. The default covers the countdown from the Saturday delivery guide (.delivery-countdown__main), the Estimated delivery section (.fdd__main) and the line from the dispatch time guide (.dispatch-time). For anything else, right-click your delivery text, choose Inspect, and add its class. The bar watches that element directly, so a countdown in a different section still ticks in the bar.

Test it on a phone

  1. Load a product: no bar.
  2. Scroll past Add to cart: the bar slides up with the title, price and delivery line.
  3. Change the variant to a sold-out one, scroll down: the bar's button says Sold out and does nothing.
  4. Tap the bar's button on an available variant: the item is added exactly as if you'd tapped the main button (cart drawer or notification included).
  5. Scroll back up to the main button: the bar disappears.

The delivery line in the bar has to come from somewhere

The bar is free: everything you need is above. What it shows underneath the button is whatever delivery text your page already has. If you don't have one yet, the Estimated delivery section adds a live cut-off countdown and a delivery date range with theme editor settings, and the bar picks it up automatically (.fdd__main is in the default selector). £12 one-off, for one store. If you'd rather not pay, the Saturday delivery countdown and dispatch time guides give you free lines it also picks up.

Buy the Estimated delivery section, £12 See pricing

FAQ

Will it add the wrong variant?

No. It doesn't have its own variant picker or form. It presses the main Add to cart button, which uses whatever variant and quantity are selected on the page.

Can I add a variant picker to the bar?

Not in this version, on purpose. A second picker has to be kept in step with the first. The bar is for shoppers who already chose a variant and scrolled down to read.

Does it work with the cart drawer?

Yes. Dawn opens the drawer, the notification or the cart page, whichever Cart type you've chosen, because the real button did the adding.

Why is it hidden on desktop?

Dawn's Enable sticky content on desktop setting keeps the whole buy box in view on wide screens. Set phone_only to false if you still want the bar there.

Does it slow the page down?

It's about 5 KB of inline code and loads nothing else. Browser observers watch the button and the text it copies, so there's no polling loop.