Work with the cart in your theme code
For theme developers: open the cart from your own buttons, keep counts in step, and style it safely.
Attravo TeamUpdated 1 min readOn this page
The cart works without theme edits. If you build custom buttons or sections, these hooks let them work with it.
Open the cart from your own button
Add the data-avc-cart-open attribute to any element, and a click on it opens the drawer:
<button type="button" data-avc-cart-open>View cart</button>
From a script, call window.avcCartOpen() once the page has loaded.
Your theme's usual cart icon and links to /cart open the drawer already, so most themes need neither.
Add products from your own code
Products added with your store's standard cart requests, from a form posting to /cart/add or a script calling /cart/add.js, are picked up by the cart, which then opens with the product in it. Other apps' add-to-cart buttons work the same way.
Keep your theme in step
After every change it makes, the cart:
- updates the cart counts your theme shows, such as the header bubble;
- sends
cart:refreshandcart:updatedevents ondocument, for a theme or app that listens for them.
Style it
The drawer's elements sit under .avc-cart and the full cart page's under .avc-pgcart. Use the design settings first, and add CSS on Pro for the rest. See Style the cart with custom CSS.
Was this helpful?
More in Troubleshooting
- The cart doesn't show on my storeWork through the usual reasons the new cart is not appearing, from the app embed to a draft theme or a cached page.
- What the warnings on Cart settings meanEach note Cart settings can show at the top of the page, what causes it, and how to clear it.
- A discount code won't applyWhy a shopper's code can be refused alongside the cart's offers and rewards, and the settings that let it through.
- Use the cart with other apps and themesHow the cart takes over your theme's cart, works with other apps' add-to-cart buttons and discounts, and what to do when two carts open.