Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

[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)