How to guides
Open Mini Cart on Add to Cart
Learn how to enable the mini cart to automatically open when clicking the add to cart button
Overview
This guide will show you how to configure your sections to automatically open the mini cart when a customer clicks the add to cart button. This feature provides immediate feedback to customers and makes it easier for them to review their cart contents.
Implementation
Add Functions to Hook
Add these functions to your template’s JavaScript hooks:
Theme-Specific Implementation
For this to work, you need to find and use the correct selectors and events from your theme’s code:
- Find the mini cart drawer element in your theme (usually has a class like
drawer-cart
ormini-cart
) - Identify the correct class that indicates the cart is visible (often
drawer--visible
or similar) - Locate the theme’s cart initialization and reload events
- Find the correct drawer event dispatch method
How It Works
- The
loadAjaxCart
function checks if the mini cart is currently visible by looking for thedrawer--visible
class - The
unloadAjaxCart
function handles the opposite case, checking when the mini cart should be closed - When a cart operation completes,
onCartOperationComplete
is triggered:- It dispatches
theme:cart:init
event to initialize the cart - It dispatches
theme:cart:reload
event to refresh cart contents - It opens the mini cart drawer using
dispatchDrawerEvent
- A 1-second delay ensures smooth operation
- It dispatches
Support
If you need help with implementing this feature, contact our support team at support@glood.ai