[Flow Theme] Open Cart Slider using custom ajax add to cart script

[Flow Theme] Open Cart Slider using custom ajax add to cart script

Ritik
Shopify Partner
7 0 1

Hello All,
I have created custom ajax add to cart functionality in my store and I want to open the slider cart after successful add to cart event. I have achieved it using the help from other discussion but it only works for the first time. If you remove the products from cart and try to add again then it won't work or if you want to add more to it then also it won't work. I am using shopify flow theme. 
$.ajax({
url: '/cart/add.js',
type: 'post',
dataType: 'json',
contentType: "application/json",
data: JSON.stringify({ 'items': itemsToAdd }),
success: function(response) {
console.log('Both products added', response);
var cartDrawerButtonSelector = ".js-drawer-open-right-link";
var cartDrawerButton = document.querySelector(cartDrawerButtonSelector);
cartDrawerButton.click();
},
error: function(xhr, status, error) {
console.error('Failed to add products', xhr.responseJSON);
}
});
Please help me out on this.
Thanks to all.

Replies 0 (0)