I am trying to add a short script to theme.liquid that detects whenever the cart is updated.
Here’s what I have right now, but it is not working when I click “add to cart” on my default store theme:
document.addEventListener('cart:updated', function(event) {
console.log('cart updated!');
});
Hi @straversi ,
I realize there are PUBSUB EVENTS on free themes, you can try this
if (window.publish !== undefined && window.subscribe !== undefined && PUB_SUB_EVENTS?.cartUpdate !== undefined) {
window.subscribe(PUB_SUB_EVENTS.cartUpdate, (e) => console.log(e));
}
Here is the results when I
- add to cart
- Increase/Decrease quantity or Remove cart items
1 Like