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.

Preview with sample data

Open in new tab

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.

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.

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 – Shopify product details component screenshot
Sticky Add to Cart Bar for Shopify · Shopify Product Details

More Product Details

Bootstrap Product Page – Bootstrap 5 product details preview

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 – Tailwind CSS product details preview

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.

Product Detail with Image Zoom Lens – Tailwind CSS product details preview

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.