Item.added event not triggering?

I’m trying to follow this tutorial JS SDK to open the cart summary/checkout page to redirect directly to the checkout (bypass the cart page) when adding an item to cart, but the item.added event does not return anything when I try to log it to the console.

The snipcart.ready and item.adding events do return, so I have verified that it is initialised and installed properly, however the item.added final state is never reached. Any help?

Can you check if you have your setup to something similar? I tested on my site and seems to be working

      document.addEventListener("snipcart.ready", () => {'item.added', (cartItem) => {
    window.location.hash = '/checkout'


Sorry you’re right, that works! However I noticed that the event does not trigger when adding a second unit of the same item to the cart.

So if I don’t have a certain product (let’s say it’s a mug) in my cart, and I add it, the item.added event is triggered. However if I then add another mug to my cart the event no longer triggers.

The item.adding event does work across both cases though. Is this a bug maybe?

@nzxh I’m having the same problem, did you find a fix to this by any chance?

Hey, I didn’t sorry :frowning: I ended up going without this feature/function

@nzxh thank you for the quick reply! Much appreciated.

I’m trying to show the cart total in my app header (Next.js) – but in order to do that, I need to be able to somehow know when an item is added so that I can update the figures accordingly.

I guess this isn’t possible then?