Does Shopify.onCartUpdate function trigger with ajax product addition?

follano
Visitor
3 0 3
Does this function fire when a product is added to cart through ajax? 
 
Shopify.onCartUpdate = function(cart) {
  alert('There are now ' + cart.item_count + ' items in the cart.');
};
 
I tried using it multiple time when a user adds product to cart and nothing is happening?
Replies 4 (4)

xinghul
Shopify Partner
7 0 0

Same question here, seems like it's not fired when items are added to the cart.

 

What is the best way to listen to cart updates using ScriptTag?

manuelmontoya
Shopify Partner
11 0 3

Same here, it looks like everybody is hijacking the "fetch" function to intercept the calls, but Shopify should have an API to avoid that.    

coalescecreate
Shopify Partner
12 2 2

Seems to work for me.

Added this mainly for people who have searched for Shopify.onCartUpdate

 

Some debugging ideas:

If you're working with someone else's theme maybe insert your script before the theme's script but after the vendors file.

Maybe your theme isn't using the Shopify library to update the cart. Below is one way to check.

coalescecreate_0-1644496963011.png

 

zhicheng1
Shopify Partner
28 2 6

What are you even talking about?

 

When I assigned a function to Shopify.onCartUpdate, it had no effect after adding an item to the cart.

 

32175be8-9915-4fa5-876f-820cc7d0ff16.png

Screenshot 2023-06-06 181527.pngScreenshot 2023-06-06 181914.png