Skip to content
Advertisement

Open Cart drawer on add to cart button click shopify

in my shopify webshop I want to open the cart drawer, if the user clicks the add to cart button. I managed to do this with this code snippet:

$(document).ready(function() {
  // Open cart drawer after add to cart button is clicked
  $('.product__add-to-cart-button').one('click', function(){
    setTimeout(function(){ $('.ajax-cart__toggle').click() }, 1500);
  });
});

But with this code, 2 units of the product are added to the cart, instead of one. Here is the link of my webshop, in case you want to try: www.wunderrein.at

I use the shopify theme Narrative.

How should I alter the code?

Advertisement

Answer

In case someone has the same issue. I found a solution for this. I exchanged .ajax-cart__toggle with .site-header__cart, which is the right selector i think.

Here is the code:

  $(document).ready(function() {
  // Open cart drawer after add to cart button is clicked
  $('.product__add-to-cart-button').one('click', function(){
    setTimeout(function(){ $('.site-header__cart ').click() }, 1500);
  });
});
Advertisement