Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Last active December 15, 2015 18:59
Show Gist options
  • Select an option

  • Save msmithstubbs/5308518 to your computer and use it in GitHub Desktop.

Select an option

Save msmithstubbs/5308518 to your computer and use it in GitHub Desktop.
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
$('#productinfo #detail #purchase').removeClass('disabled').removeAttr('disabled'); // remove unavailable class from add-to-cart button, and re-enable button
var newHtml = Shopify.formatMoney(variant.price, "");
if(variant.compare_at_price > variant.price) {
newHtml += '<div class="was-price">was ' + Shopify.formatMoney(variant.compare_at_price, "") + '</div>';
}
$('#price-field').html(newHtml); // update price field
// added for Back In Stock app
if (variant.inventory_quantity == 0) { // some products are out of stock, but still available
$('#BIS_trigger').show();
} else {
$('#BIS_trigger').hide();
}
} else {
// variant doesn't exist
$('#productinfo #detail #purchase').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "This Size is Sold Out" : "Unavailable";
$('#price-field').text(message); // update price-field message
$('#BIS_trigger').show(); // added for Back In Stock app
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment