I am using add to cart with custom ajax code and its working fine, problem is I need to open cart drawer on success function by using timber.RightDrawer.open();
For now I am using “js-drawer-open-right” class in form but its open drawer same time when click on add to cart button. I need to open drawer on success of add to cart.
My Ajax code is:
function addItem(button) {
var postData = $(button).closest('.add-to-cart').serialize();
$.ajax({
type: 'POST',
url: '/cart/add.js',
dataType: 'json',
data: postData,
success: addToCartOk,
error: addToCartFail
});
}
function addToCartOk(product) {
//Want to open drawer here on success
timber.RightDrawer.open();
}
function addToCartFail(obj, status) {
}
My form is:
Here you can check Add to Cart https://soft-theme.myshopify.com/collections/all
2
Answers
I have find out different and very easy solution for this as compare to timber.RightDrawer.open();
I have clicked "js-drawer-open-right" with jQuery in success function and removed that class from form which I have placed before.
The success function now is:
Its worked perfectly fine.
@barjinder solution but cleaner:
You can use the below form