Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save msmithstubbs/5223114 to your computer and use it in GitHub Desktop.
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('#add-to-cart').removeClass('disabled').removeAttr('disabled').val('Add to Cart'); // remove unavailable class from add-to-cart button, and re-enable button
if(variant.price < variant.compare_at_price){
jQuery('#price-preview').html(Shopify.formatMoney(variant.price) + " <span>was " + Shopify.formatMoney(variant.compare_at_price) + "</span>");
} else {
jQuery('#price-preview').html(Shopify.formatMoney(variant.price));
}
jQuery('#BIS_trigger').hide(); // This line added for Back In Stock app
} else {
// variant doesn't exist
var message = variant ? "Sold Out" : "Unavailable";
jQuery('#add-to-cart').addClass('disabled').attr('disabled', 'disabled').val('Sold Out'); // set add-to-cart button to unavailable class and disable button
jQuery('#product .variants .price').text(message); // update price-field message
jQuery('#BIS_trigger').show(); // This line added for Back In Stock app
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment