, e.g. "(05/11/2026)"
var rawDue = $el.find("small").text();
// Classes - kept identical to the original script for each case
if ($el.hasClass("out-stock") && omIsLive($el)) {
// supplier_1001 out of stock -> checkstock button (text-danger stays, as before)
$el.removeClass("out-stock").addClass("checkstock-btn defaultbtn");
} else if ($el.hasClass("no-stock-no-chat")) {
// no stock and no chat flag from the platform -> checkstock button
$el.removeClass("no-stock-no-chat").addClass("checkstock-btn defaultbtn");
} else if ($el.hasClass("out-stock")) {
// other suppliers out of stock
$el.addClass("defaultbtn").removeClass("text-danger");
} else {
// "0 In Stock"
$el.removeClass("in-stock").addClass("checkstock-btn defaultbtn");
}
// Button text, plus the hidden due date for non-live products
// (live products get their date from the API on click instead)
var due = omDueDate(rawDue);
var html =
"" +
omStock.labels.outOfStock +
"";
if (due && !omIsLive($el)) {
html +=
"" +
omStock.labels.stockDue +
"" +
due +
"";
}
$el.html(html).attr("data-om-state", "check").css("cursor", "pointer");
// one "Chat Now" button per stock button (hidden until needed)
if (!$el.next(".out-stock-chat-checkstock").length) {
$el.after(
"" +
(window.svgChatIcon || "") +
omStock.labels.chatNow +
"
",
);
}
}
/* ---------- convert the platform's stock labels ---------- */
// Runs over every stock label that hasn't been processed yet and applies the rules:
// 4+ left alone, 1-3 -> Low Stock, 0 / out-stock / no-stock-no-chat -> Check Here button.
// Safe to call repeatedly - processed elements are skipped via data-om-state.
function omProcessStock() {
$(".live-inventory-v2-shipping")
.not("[data-om-state]")
.each(function () {
var $el = $(this);
// product-ajax.js re-runs stockChecker() when a product variant changes and the
// platform re-renders the stock label - remove any "Chat Now" button left over
// from the previous variant so it doesn't stay on screen
$el.siblings(".out-stock-chat-checkstock").remove();
if ($el.hasClass("in-stock")) {
var qty = omParseQty($el.text());
if (qty !== null && qty <= 0) {
omMakeOutOfStock($el);
} else if (
omStock.showLowStock &&
qty !== null &&
qty <= omStock.lowStockMax
) {
omShowLowStock($el);
} else {
$el.attr("data-om-state", "done"); // normal in stock - nothing to change
}
} else if (
$el.hasClass("out-stock") ||
$el.hasClass("no-stock-no-chat")
) {
omMakeOutOfStock($el);
}
// anything else (e.g. inventory location links, not populated yet) is left alone
});
// labels are hidden on load by stockChecker() - show them once processed,
// but leave any label we've swapped for the "Chat Now" button hidden
$(".live-inventory-v2-shipping").not("[data-om-chat]").fadeIn();
}
/* ---------- click: "Out of Stock – Check Here" ---------- */
// Delegated, so it also works for products loaded later by AJAX.
// Non-live products: reveal the due date, or show Chat Now if there isn't one.
// Live products (supplier_1001): ask the stock API, then show in stock / low / due date / chat.
$(document).on(
"click",
".live-inventory-v2-shipping[data-om-state='check']",
function (e) {
e.preventDefault();
var $el = $(this);
// Other suppliers: the due date came with the page
var $due = $el.find(".stock-due-details");
if ($due.length) {
$el.find(".product-stock-click-here").hide();
$due.show();
omDone($el);
return;
}
if (!omIsLive($el)) {
omShowChat($el);
return;
}
// supplier_1001: ask the live stock feed
$el
.attr("data-om-state", "loading")
.css("cursor", "default")
.html(omStock.labels.loading);
$.getJSON(omStock.apiUrl + encodeURIComponent(omSku($el)))
.done(function (data) {
var stock = parseInt(data && data.Stock, 10) || 0; // negative/blank stock counts as 0
var due = omDueDate(data && data.NextStockDueDate);
if (
stock > omStock.lowStockMax ||
(stock > 0 && !omStock.showLowStock)
) {
// plenty in stock - or Low Stock is switched off, so show the real number
omShowInStock($el, stock);
} else if (stock > 0) {
$el.removeClass("text-danger checkstock-btn defaultbtn");
omShowLowStock($el);
} else if (due) {
omShowDue($el, due);
} else {
omShowChat($el);
}
})
.fail(function () {
omShowChat($el); // can't check -> offer chat
});
},
);
/* ---------- click: "Chat Now" ---------- */
// Opens the Zendesk (Zopim) live chat and sends the product SKU.
// chatFunction() also binds .out-stock-chat-checkstock directly - if it has,
// we skip so the chat isn't opened twice.
$(document).on("click", ".out-stock-chat-checkstock", function () {
var events = $._data(this, "events");
if (events && events.click) return;
var sku = omSku($(this));
try {
if (window.$zopim && $zopim.livechat) {
$zopim.livechat.window.show();
if (sku) $zopim.livechat.say(omStock.chatMessage(sku));
}
} catch (err) {
console.warn("Stock chat could not be opened", err);
}
});
/* ---------- layout + start-up ---------- */
// Moves the stock labels into position (unchanged from the original script),
// then processes them 1 second after the page is ready, once the platform has filled them in.
// NOTE: product-ajax.js also calls stockChecker() on product pages (on load and on every
// variant change via evoXProductChangeCallback) - keep this function name the same.
function stockChecker() {
// hide labels until they've been processed, to avoid a flash of the raw text
$(".live-inventory-v2-shipping").hide();
// product tiles (listings): move the stock label to just under the product name
$(".tileparent .footer").each(function () {
var inventoryWrapper = $(this).find(".live-inventory-v2-wrapper");
var productName = $(this).find(".product-name");
inventoryWrapper.insertAfter(productName);
inventoryWrapper.addClass("stock-indicators-wrapper list");
});
// product page (mobile + desktop): move the stock label into the product details
$(".mobile .product-shopping-actions-row .live-inventory-v2-wrapper")
.appendTo(".mobile .productdetails")
.addClass("stock-indicators-wrapper stockCheaker");
$(".desktop .product-shopping-actions-row .live-inventory-v2-wrapper")
.appendTo(".desktop .productdetails")
.addClass("stock-indicators-wrapper stockCheaker");
$(".mobile .stockCheaker").appendTo(".mobile .productdetails .pdp-prod-info");
$(".desktop .stockCheaker").appendTo(
".desktop .productdetails .pdp-prod-info",
);
$(document).ready(function () {
setTimeout(omProcessStock, 1000); // adjust the delay as needed
});
}
stockChecker();
// Re-run for products that load later (filters, paging, live inventory refresh).
// Debounced so lots of AJAX calls in a row only trigger one pass.
var omStockTimer;
$(document).ajaxComplete(function () {
clearTimeout(omStockTimer);
omStockTimer = setTimeout(omProcessStock, 300);
});