Solved

Why isn't my "Add to Cart" snippet for Canopy theme/Shopify 2.0 working for my class button?

  • 16 April 2022
  • 1 reply
  • 213 views

Badge +2

I'm struggling here. I'm using Canopy Theme and when we updated to Shopify 2.0, it knocked out our Added to Cart code. Now I can't get it to work again.

 

Here's my button code:

 

<button type="submit" name="add" class="btn product-add mini-form" data-btn-type="add-to-cart">

              <span class="button-text">Add to cart</span>

              <span class="loading-spinner" aria-label="Adding"></span>

             </button>

 

Here's where I customized the snippet:

 

<script type="text/javascript">
var _learnq = _learnq || [];
  var classname = document.getElementsByClassName("btn product-add mini-form" data-btn-type="add-to-cart");
var addToCart = function() {
_learnq.push(['track', 'Added to Cart', item]);
}; for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', addToCart, false);
}
</script>

 

 

Did I customize the snippet incorrectly?

 

Thanks!

 

 

icon

Best answer by Taylor Tarpley 18 April 2022, 16:59

View original

1 reply

Userlevel 7
Badge +60

Hi there @reneewood8

 

Happy to help!

 

Have you tried removing the “data-btn-type=”add-to-cart” section from your snippet and only having the “btn product-add mini-form” within the parentheses after the .getElementsByClassName section of your snippet? When adding in the class snippet,  you should only add what’s in the quotation marks for the ‘Added to Cart’ for the class button snippet, as seen below.

 

I can see that we have an awesome member of our support team helping you troubleshoot this problem, however, i would double check that this isn’t what’s causing the metric not to fire along with following along with our support team members last bit of instructions! Additionally, we also have a guide for Shopify 2.0 themes specifically,, you will need to add this snippet to the custom liquid block. 

 

Hope this helps!

-Taylor 

Reply