Skip to content

Sticky Add to Cart Bar for Shopify

Shopify section: a bar fixed to the bottom of product pages that appears once the main add-to-cart button scrolls away, with image, price, variant select and a real product form.

Also known as: sticky buy button, fixed add to cart bar, floating add to cart, sticky product bar

Preview with sample data

Open in new tab

Liquid code

A sticky add to cart bar for Shopify: a Liquid section that keeps the product image, title, price, variant select and buy button on screen after the shopper has scrolled past the main button. Add it to a product template; no app is needed.

How it works

The bar is fixed to the bottom of the page and stays hidden while the theme's main add-to-cart button is in view. An IntersectionObserver watches that button, and the .is-visible class slides .wds-sab in once the button has left the top of the screen.

By default the section finds the theme's product form on its own by looking for a form that posts to /cart/add. The form inside the bar is built with Shopify's form 'product' tag, so it submits to the cart the same way a theme's product form does.

Choosing a variant updates the price, compare-at price and sold-out state. When the bar appears it copies the variant picked in the main form, and on submit it copies filled properties[...] fields from that form, so line item properties are kept. While visible, the bar reserves space at the bottom of the page so it never covers the footer.

Customization

In the theme editor, the section is called WDS Sticky add to cart:

  • Custom add-to-cart selector: optional CSS selector of the main button or form, for themes where automatic detection does not find it.
  • Add button, Sold out: the labels on the button.
  • Variant select (screen readers), Bar name (screen readers): hidden labels.
  • Background, Text, Accent (button), Button text: the four colors of the bar.
  • Side padding, Top padding, Bottom padding: spacing around the content.

Use cases

  • Long product pages: shoppers keep the buy button in reach after scrolling past reviews and descriptions
  • Mobile shoppers: a bar fixed to the bottom of the screen shows price and variant select without scrolling back
  • Stores with many variants: choosing a variant in the bar updates price, compare-at price and sold-out state
  • Product pages without an app: add the section to an Online Store 2.0 product template and skip a paid app

Accessibility

The bar is a named region with a real label on the variant select and aria-live="polite" on the price. While keyboard focus is inside it, the bar stays visible. Controls have visible focus and at least 44 px height, and the slide animation is turned off for prefers-reduced-motion.

Usage notes

It requires an Online Store 2.0 theme, because it is added as a section to a JSON product template. It renders nothing on non-product pages, and it also hides itself for products that can only be bought with a subscription plan. If your theme has its own sticky bar, turn that one off.

Limits to know about: there is no quantity selector, so the bar adds the variant's minimum quantity. Variants are shown in one select rather than one per option. A change made in the bar's select does not update the theme's main picker.

The preview runs on sample data for an invented store, inside a sample product page that is not part of the section. It loads just past the main button; the "Demo" button scrolls up and back so you can see the bar hide and return. Add to cart is simulated there. Photos in the preview are from Unsplash; section.liquid contains none and uses your product's own images.

Sticky Add to Cart Bar for Shopify at a glance

Framework
Shopify
Code
Liquid
JavaScript
A small script inside the section, no jQuery
Dependencies
fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Product Details
License
Free for personal and commercial use

Questions about this section

Can I use the Sticky Add to Cart Bar for Shopify code for free?

Yes. You can copy or download the Liquid code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my Shopify store?

Create a new section named shopify-sticky-add-to-cart in your theme code editor, paste the Liquid code and save. Then add the section to a page in the theme editor. It works with Online Store 2.0 themes.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

How to install

  1. In your Shopify admin, go to Online Store > Themes, open the theme's menu and choose Edit code.
  2. Under Sections, add a new section named shopify-sticky-add-to-cart, replace its contents with the Liquid code above and save.
  3. Open the theme editor, choose Add section and add it to the page.

Requires an Online Store 2.0 theme. Try it on a copy of your theme first. WebDevSnippets is not affiliated with or endorsed by Shopify.

Sticky Add to Cart Bar for Shopify – free Shopify product detail page template
Sticky Add to Cart Bar for Shopify · free Shopify product detail page template

More Product Details

Bootstrap Product Page – free Bootstrap 5 product detail page template

Bootstrap Product Page

Bootstrap 5 product details page with image gallery, color and size pickers, quantity stepper, and tabs for description, specifications and customer reviews.

Product Detail with Gallery – free Tailwind CSS product detail page template

Product Detail with Gallery

Dark Tailwind CSS product page section with a thumbnail image gallery, finish options, quantity stepper and add to cart button with loading state.

Frequently Bought Together Section for Shopify – free Shopify product detail page template

Frequently Bought Together Section for Shopify

Shopify section that shows the current product with up to 3 picked products, checkboxes, variant selects, a live total and one button that adds everything checked to the cart.

Product Detail with Image Zoom Lens – free Tailwind CSS product detail page template

Product Detail with Image Zoom Lens

Tailwind CSS product detail section with a round magnifier lens that zooms the photo on hover or arrow keys, plus adjustable 2x to 4x levels.