Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Last active December 20, 2015 03:39
Show Gist options
  • Select an option

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

Select an option

Save msmithstubbs/6065703 to your computer and use it in GitHub Desktop.
{% if product.available %}
<style>
#BIS_trigger { display: none; }
</style>
{% endif %}
<script type="text/javascript">
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
$('#BIS_trigger').hide(); // added for Back In Stock
} 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 ? "Sold Out" : "Unavailable";
$('#price-field').text(message); // update price-field message
$('#BIS_trigger').show(); // added for Back In Stock
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment