The add to cart button on a Shopify theme: what you can change, and why it stops working

On a Shopify theme, the add to cart button is the submit button of the product form, shown by the Buy buttons block on the product page. You change its text, style and the checkout buttons beside it without code. When it stops working, the cause is usually the variant, an app, a script error or the product template.

A frosted purple glass shopping basket with a glass plus sign floating above it and a lime green ball beside it, on a dark violet surface.

What the button is, inside the theme

Three pieces work together.

The product form. Every product page has a form that Shopify’s Liquid builds with {% form 'product' %}. Inside it there is a hidden field with the ID of the selected variant, and a submit button. That button is “Add to cart”. When a customer picks a size or a color, the theme’s JavaScript writes the new variant ID into the hidden field. The cart receives a variant, never a product.

The Buy buttons block. In the theme editor, the form shows up as a block called Buy buttons, inside the Product information section. It holds the add to cart button and the accelerated checkout buttons. In Shopify’s Dawn and Horizon themes it also holds the gift card recipient form, and in Horizon the pickup availability.

Accelerated checkout buttons. Older themes call them dynamic checkout buttons. They sit under add to cart and send the customer straight to checkout with that product. The unbranded one reads “Buy it now”. The branded ones (Shop Pay, Apple Pay, Google Pay, PayPal and others) appear according to the payment methods active on the store and the customer’s device. You cannot choose which one shows, or restyle the branded ones.

They have limits you should know before you turn them on. They buy one variant at a time. They skip the cart, so they do not carry cart attributes: if your cart has a terms checkbox, a gift note or a delivery date, a customer who uses them never sees it. Shopify also warns that they can conflict with apps that act on the cart.

What you can change without code

  • Show or hide the checkout buttons. Open the product template in the theme editor, click Buy buttons in the Product information section, and use the checkbox. Shopify’s help center calls it “Show accelerated checkout buttons”; Dawn labels it “Dynamic checkout buttons”.
  • Hide the button on some products. Create a second product template, hide the Buy buttons and Quantity selector blocks with the eye icon, and assign it to those products from the Theme template menu on the product in the admin.
  • The text. In the admin, under Online Store, open the menu next to your theme and choose Edit default theme content. Search for “Add to cart”, “Sold out” or “Unavailable” and write your own.
  • Colors and shape. Buttons take their look from the theme settings, so a change there applies to the whole store.
  • What happens after the click. In Dawn, under Theme settings, Cart, the cart type can be Drawer, Page or Popup notification. Horizon offers Page or Drawer, with an option to open the drawer after add to cart.
  • Where the block sits. You can drag Buy buttons above or below the other blocks of the section.

What needs code

  • A label that changes by product, for example “Pre-order” for products with a tag or a future date.
  • Fields the customer fills in before adding, such as an engraving text or an uploaded file. They are line item properties, and they have to sit inside the product form to reach the order.
  • Adding several products with one click (a bundle, a product plus its accessory).
  • A button that replaces add to cart for some customers, such as “Request a quote” on a B2B store.
  • A sticky bar or a quick add on a theme that does not have one.

None of these is a large job. They belong in a block or a snippet, so the next theme update does not erase them.

Sticky add to cart and quick add

A sticky add to cart is a bar that keeps the button in view when the customer scrolls past the main one. It earns its place on long product pages, mostly on phones. Not every theme has it. Dawn does not. Horizon has a “Sticky add to cart bar” setting in the Product information section. Check that the bar shows the selected variant and its price, and that it does not cover a chat bubble or the cookie banner.

Quick add puts the button on the product cards of a collection. In Dawn it is a setting of the product grid, with the values None, Standard and Bulk. In Horizon it is under Theme settings, Product cards, with a separate switch for phones. With one variant, the product goes straight into the cart. With several, the card opens a small window to choose first.

The Universe theme by Developpy, our theme on the Shopify Theme Store, includes a sticky add to cart bar, quick add and quick view on every product card, and a cart drawer with cross-sell and a free shipping progress bar, with no apps.

Why it stops working, and how to find which cause

We go from the product to the code. Start with the question that saves the most time: does it fail on every product or on one?

1. The variant

If the button is gray and reads “Sold out”, the selected variant has no stock and is not set to continue selling when out of stock. If it reads “Unavailable”, that combination of options does not exist as a variant. Open the product in the admin and check stock per variant and per location. Check also that the product is published on the Online Store channel.

2. An app that replaced the form

Subscription, bundle, pre-order and product options apps often replace the button or the whole form with their own. When the app is paused, removed or updated, the button can stay on the page and do nothing. In the theme editor, open App embeds and turn the embeds off one at a time. Then look at the Buy buttons area of the template for app blocks. Some apps write code directly into the theme files; that code can stay after the app is uninstalled, and it takes a developer to remove it cleanly.

3. A script error

The click is handled by JavaScript. If another script on the page fails first, the button can stop responding. Open the product page in Chrome, right-click, choose Inspect and open the Console tab. Reload, click the button and read the first red line: the file name often names the app or the snippet at fault. In the Network tab, a request to /cart/add.js that answers with status 422 means Shopify refused the product, and the answer says why (sold out, or more than the stock left).

4. A broken product template

If it fails on some products only, compare their template. In the admin, the Theme template menu on the product shows which one it uses. That template may have the Buy buttons block hidden or deleted. If it fails everywhere, preview a fresh, unmodified copy of your theme. If the button works there, the fault is in your theme’s code. The code editor keeps earlier versions of each file, so a recent edit can be rolled back.

When to hand it over

You can do the variant, app embed and template checks yourself. Hand it over when the console shows errors in theme files, when the form was rewritten by an app that is no longer installed, or when the button fails only on some devices. Fixes like these are part of our Shopify support retainers: we reproduce the fault on a copy of the theme, fix it there, and tell you what caused it.

Keep reading

Tell us what you are working on

Book a 15-minute call, or write to us.

Book a call (opens in a new tab)