HOW2 SHOPIFY: Add a Sticky Add-to-Cart Bar to Any Theme Without an App

HOW2 SHOPIFY: Add a Sticky Add-to-Cart Bar to Any Theme Without an App

aop3d tech
HOW2 SHOPIFY

Add a Sticky Add-to-Cart Bar to Any Theme Without an App

Here's the conversion leak nobody talks about: on mobile, the buy button scrolls away the moment a shopper reads your description. A sticky add-to-cart bar pins it to the screen — product name, price, and buy button, always one tap away. Build it in 15 minutes with a few dozen lines of code. No app, no monthly fee.

Why It Works

Every scroll away from your buy button is a chance to bounce. A sticky bar fixes three problems at once:

  • Zero scroll-back: the buy button is always visible, even at the bottom of a long description.
  • Mobile-first: thumb-friendly, one-tap purchasing on the device where most stores earn 70%+ of traffic.
  • Price confidence: keeping the price in view removes the "wait, how much was it?" moment that kills momentum.

Step 1: Create the Snippet

In your Shopify admin, go to Online Store > Themes, click the ... menu on your live theme, and choose Edit code. Under Snippets, click Add a new snippet and name it sticky-cart-bar. This keeps your code isolated, so it survives theme updates cleanly.

Step 2: Paste This Code

Replace the snippet's contents with the following. It shows a bottom-fixed bar once the shopper scrolls past your main buy button, and its button clicks your theme's own add-to-cart form — so it works with variants, quantity pickers, and most theme setups:

<div id="aop3d-sticky-bar" hidden style="position:fixed;left:0;right:0;bottom:0;z-index:9999;display:flex;align-items:center;gap:12px;padding:12px 16px;background:#0f172a;color:#f8fafc;box-shadow:0 -4px 16px rgba(0,0,0,.25);">
  <div style="flex:1;min-width:0;">
    <div style="font-weight:700;font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{ product.title | escape }}</div>
    <div style="font-size:14px;opacity:.85;">{{ product.price | money }}</div>
  </div>
  <button id="aop3d-sticky-btn" type="button" style="background:#f59e0b;color:#0f172a;border:none;border-radius:999px;padding:12px 24px;font-weight:700;font-size:15px;cursor:pointer;">Add to Cart</button>
</div>
<script>
(function(){
  var bar = document.getElementById('aop3d-sticky-bar');
  var btn = document.getElementById('aop3d-sticky-btn');
  var main = document.querySelector('form[action*="/cart/add"] [type="submit"]');
  function onScroll(){
    if(!main){ bar.hidden = false; return; }
    bar.hidden = main.getBoundingClientRect().bottom > 0;
  }
  window.addEventListener('scroll', onScroll, {passive:true});
  onScroll();
  btn.addEventListener('click', function(){
    if(main){ main.scrollIntoView({behavior:'smooth',block:'center'}); main.click(); }
    else{ window.scrollTo({top:0,behavior:'smooth'}); }
  });
})();
</script>

Because the sticky button clicks your existing buy button rather than building its own cart form, it inherits your theme's variant logic automatically.

Step 3: Render It in Your Theme

Open Layout > theme.liquid, find </body> near the bottom, and paste this line right before it:

{% if template contains 'product' %}
  {% render 'sticky-cart-bar' %}
{% endif %}

Save, then test on a real product page:

Check What to look for
Scroll behavior Bar appears only after the main buy button scrolls out of view
Variant products Pick a size/color, tap the sticky button — the right variant lands in the cart
Mobile view Bar stays above your cookie banner and chat widget, nothing overlaps
Cart flow The sticky button triggers your normal cart drawer or cart page, exactly like the main button

Tune It to Your Brand

  • Swap #f59e0b for your brand's accent color and #0f172a for a matching dark tone.
  • If the bar covers your chat widget, raise the chat's z-index in your theme settings or lower the bar's.
  • Hide it on desktop if you only want it on mobile: wrap the render in a media query check or a simple CSS rule.

Quick Recap

  • Create a sticky-cart-bar snippet with the code above.
  • Render it before </body> on product pages.
  • Test variants, mobile overlap, and the normal cart flow.

Total cost: zero. Total benefit: your buy button never leaves the screen again.

Disclaimer: The tech tips provided in this article are for informational purposes only. AOP3D TECH is not responsible for any data loss or hardware damage. Always back up your devices before attempting troubleshooting.

Back to blog