Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Created March 16, 2012 21:14
Show Gist options
  • Select an option

  • Save carolineschnapp/2052746 to your computer and use it in GitHub Desktop.

Select an option

Save carolineschnapp/2052746 to your computer and use it in GitHub Desktop.
Showing or hiding a back-order message
var selectCallback = function(variant, selector) {
if (variant && variant.available) {
if (variant.inventory_management != '' && variant.inventory_quantity < 0) {
$('.backorder').show();
}
else {
$('.backorder').hide();
}
$("input#add").removeClass("disabled").removeAttr("disabled");
$("h2#price span").html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));
if (variant.compare_at_price) {
$("h2#price del").html(Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}"));
}
else {
$("h2#price del").empty();
}
}
else {
$('.backorder').hide();
$("input#add").addClass("disabled").attr("disabled", "disabled");
var message = variant ? "Sold Out" : "Unavailable";
$("h2#price span").text(message);
$("h2#price del").empty();
}
};
@carolineschnapp

Copy link
Copy Markdown
Author

There are like 3 situations here: is unavailable/sold out (1), is back-order (2) and is in stock (3).
The difference between (2) and (3) is ONLY the backorder message - for it to be shown or hidden.
Everything else is the same, that is, in both (2) and (3) we do NOT disable the add to cart button, we DO show the price, etc. It's business as usual, only difference is showing or not the backorder message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment