Created
August 15, 2014 19:58
-
-
Save cshold/93b6bf8b90a6adbb68c0 to your computer and use it in GitHub Desktop.
Shopify Ajax Cart Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're fantastic, thanks!