Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Created November 18, 2011 20:16
Show Gist options
  • Save carolineschnapp/1377624 to your computer and use it in GitHub Desktop.
Save carolineschnapp/1377624 to your computer and use it in GitHub Desktop.
Fix for On the Go theme
<!-- BEFORE -->
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('#add-to-cart').removeClass('disabled').removeAttr('disabled'); // 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, "{{ shop.money_format }}") + "<del>" + Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}") + "</del>");
} else {
jQuery('#price-preview').html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));
}
} else {
// variant doesn't exist
jQuery('#add-to-cart').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "{{ settings.tr_sold_out }}" : "{{ settings.tr_unavailable }}";
jQuery('#product .variants .price').text(message); // update price-field message
}
};
<!-- FIX -->
var selectCallback = function(variant, selector) {
if (variant && variant.available == true) {
// selected a valid variant
jQuery('#add-to-cart').removeClass('disabled').removeAttr('disabled'); // 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, "{{ shop.money_format }}") + "<del>" + Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}") + "</del>");
} else {
jQuery('#price-preview').html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));
}
jQuery('#add-to-cart').val("{{ settings.tr_add_to_cart }}"); // update button label.
} else {
// variant doesn't exist
jQuery('#add-to-cart').addClass('disabled').attr('disabled', 'disabled'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "{{ settings.tr_sold_out }}" : "{{ settings.tr_unavailable }}";
jQuery('#add-to-cart').val(message); // update button label.
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment