0
votes

I am looking for a solution about how to call a javascript function when an item is added to cart on shopify via ajax. Product can be added from homepage, collection-page or product-page.

I am trying with this method but not working for me. These changes i am doing within the theme files "theme.liquid, product.liquid, collection.liquid"

Everytime product go to cart alert should done.

Shopify.onItemAdded = function(line_item) {
        alert('success');
      };
1
Are you getting any error? Most times the code is to be added to scripts.js (or script.js) file, and often times, there'll always be something like this already. Have a look.HymnZzy

1 Answers

-1
votes

You'll want to use CartJs... is does exactly what you need and has events etc for when things are added to cart