简体   繁体   中英

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?

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);
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM