Skip to content

Instantly share code, notes, and snippets.

@cshold
Created Aug 15, 2014
Embed
What would you like to do?
Shopify Ajax Cart Callback
// Create a global function that handles all cart-related JS
initCart = function (obj) {
// Do all cart things here
// If running as the ajax cart callback, an object is returned
if (obj.is_visible) {
// the cart is shown
} else {
// the cart was hidden
}
};
// From your general JS file, run initCart() on your /cart page
initCart();
// In your theme.liquid file, initialize the ajax cart.
// Pass initCart as the callback function to onToggleCallback
// This will run the initCart function each time the cart is shown/hidden, passing an object back.
jQuery(function($) {
ajaxifyShopify.init({
method: 'drawer',
onToggleCallback: initCart
});
});
@carolineschnapp
Copy link

carolineschnapp commented Aug 15, 2014

You're fantastic, thanks!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment