onItemAdded event in ScriptTag

hassanba
New Member
3 0 0

Hi,

I'm using SriptTag and i can't find an event that can trigger on Item added to cart.
I tried:

Shopify.onItemAdded = function(lineItem) {
console.log(lineItem)
};

but it does'nt work.
How can i achieve that?

Replies 4 (4)
SBD_
Shopify Staff
1097 147 209

Hey @hassanba,

 

Not all themes will call Shopify.onItemAdded. If this is for a single store, create a function in your ScriptTag and update the theme to call that function when an item is added to cart. If you're building an app for multiple store, here's one approach to detecting an add to cart.

Scott | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

hassanba
New Member
3 0 0

Hi @SBD_ , Thanks for your answer

I tried XHR intercetor on /cart/add.js and it works like a charm

But on checkout button this XHR interceptor does'nt fire !! is there any way to listen on checkout button?

N.B: I'm building an app for multiple store

thanks a lot,

SBD_
Shopify Staff
1097 147 209

Perhaps also listen for an [action=/checkout] form submit

Scott | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

amerrnath
New Member
4 0 0

where are the api docs for these events. 
It would be helpful