Skip to content

Instantly share code, notes, and snippets.

@cshold
Created August 15, 2014 19:58
Show Gist options
  • Save cshold/93b6bf8b90a6adbb68c0 to your computer and use it in GitHub Desktop.
Save cshold/93b6bf8b90a6adbb68c0 to your computer and use it in GitHub Desktop.
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

You're fantastic, thanks!

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