Syncing cart updates with custom themes
This feature is for theme developers or merchants using custom themes with non-standard cart implementations.
Understanding the issue
In the Legacy chatbox, Chatty reloads the theme's cart-drawer and cart-icon-bubble sections after the AI adds, updates, or removes items. Themes that have these sections refresh the cart display. However, some custom themes — especially those with custom-built cart drawers or non-standard Ajax cart implementations — don't follow Shopify's standard cart behavior.
This causes a common problem: the AI successfully updates the cart, but the cart UI doesn't refresh. Customers see an outdated cart and may think the AI isn't working.
In AI Mode, the AI makes some cart changes on Chatty's server: all updates and removals, and some adds. Chatty doesn't refresh the theme's cart after those changes and doesn't send the chatty:cart:changed event. The theme shows them after the page reloads.
Signs your theme needs this fix
- Cart drawer doesn't update when AI adds products
- Cart icon badge (item count) stays the same after a product is added from the chatbox
- Cart total doesn't reflect AI-added items
In AI Mode, the fix on this page doesn't cover AI updates and removals. No theme refreshes its cart after those until the page reloads.
How Chatty cart events work
Chatty dispatches a custom JavaScript event called chatty:cart:changed when the cart changes through the chatbox. The table below shows which changes send it. Your theme can listen for this event and trigger a cart refresh.
Event details
| Event name | chatty:cart:changed |
|---|---|
| Triggered by | Shopper cart changes in the chatbox: add_to_cart, update_cart, remove_from_cart. AI changes in the Legacy chatbox send the same three actions. In AI Mode, some AI adds send add_to_cart, but AI updates and removals don't send this event. In both modes, swap_in_cart when the AI replaces a variant in the cart. Also checkout when the shopper clicks checkout in the chatbox cart, and theme_cart_changed when a cart change request runs on the page after Chatty starts watching the cart (once the visitor allows tracking or opens the chat). This can include changes your theme makes itself and Chatty's own cart requests |
| Property Type | action (string) |
How to add event to your theme
To sync your cart UI with the cart changes listed in the table above, add an event listener that refreshes your cart when the event fires.
- Open your theme's JavaScript file (commonly theme.js or cart.js).
- Add the following code:
window.addEventListener('chatty:cart:changed', function(e) {
// Skip the event Chatty sends when it sees a cart request on the page
if (e.detail.action === 'theme_cart_changed') return;
// Replace this with your theme's cart refresh function
refreshCart();
});Listen on window. Chatty sends the event on window, so a listener on document never runs.
Example: Custom Cart Drawer
window.addEventListener('chatty:cart:changed', async (e) => {
// Fetch updated cart
const cart = await fetch('/cart.js').then(r => r.json());
// Update cart count badge
document.querySelector('.cart-count').textContent = cart.item_count;
// Refresh cart drawer content
refreshCartDrawer(cart);
});Test the integration
After adding the event listener:
- Go to your store and open the chatbox
- Add a product to the cart from the chatbox
- Confirm the cart UI updates without a page refresh
- Change the quantity and remove the item in the chatbox cart
AI updates and removals send this event only in the Legacy chatbox. In AI Mode, test them from the chatbox cart instead.
If your cart still doesn't update, contact our support team through live chat in the app. Share your theme name and any console errors you're seeing.
Chatty Help Center