Add to Cart Script

The Add to Cart script is custom JavaScript that will run after a product is added to cart.

You can access this from Settings > Add to Cart Script

This is most commonly used when integrating with an Ajax Cart or Notification Popup.

If you are not a developer you should leave this alone.

It consists of two settings:

  • Section id’s to render: A comma seperated list of section id’s you want Shopify to return rendered html for when adding an item to cart. The section object will be included in addtocartresponse variable that can be referenced in Add to Cart Script.

    https://shopify.dev/api/ajax/reference/cart#bundled-section-rendering

    The rendered HTML will be updated with the recently added items in the cart. Typically you would use this because you want to render an updated cart item count or ajax drawer.

  • Script to run after add to cart: This script will run after add to cart button is pressed and the shopify cart/add.js api responds. “addtocartresponse” variable can be used in the script and will contain the api response to cart/add.js api. The response will also contain any rendered html elements included in “Section ids to render”.

    https://shopify.dev/api/ajax/reference/cart#post-locale-cart-add-js

Generally you should always leave these setting empty unless you are using an ajax drawer or really know what you are doing.