This code sets enables/disables the Add to Cart button according to the availability inventory of bundle products.
- Create a new snippet called 'bundle-sync.liquid'. Copy the code from the bundle-sync file below.
- Open theme.liquid and add
{% include 'bundle-sync' %}
to the bottom of the file, just above where it says</body>
.
Edit bundle-sync.liquid to pass additional options to the bundle sync function.
inventory
: pass this callback a function to handle updating the state of add to cart buttons. For example:
var container = $('form[action="/cart/add"]');
window.bundleSync.init({
inventory: function(available) {
var addToCartForm = $('form[action="/cart/add"]'),
addToCartButton = $('input[type=submit]', addToCartForm),
quantityContainer = $('.qty-selection', addToCartForm);
if (available > 0) {
addToCartButton.val('Add To Cart').prop('disabled', false);
quantityContainer.show();
} else {
addToCartButton.val('Not Available').prop('disabled', true);
quantityContainer.hide();
}
}
});