Skip to content
Showing the single result
$0.00 — available on subscription
-
Buy now
Go to Top
console.log("GB custom code loaded");
window.GB_OOS_SCRIPT_LOADED = true;
document.addEventListener("DOMContentLoaded", function () {
// Only run on GrowBox product page (ID 2577)
if (!document.body.classList.contains("postid-2577")) return;
// Debug flag so we can verify it loaded
window.GB_OOS_SCRIPT_LOADED = true;
function isOutOfStock(stockEl) {
if (!stockEl) return false;
if (stockEl.classList.contains("out-of-stock")) return true;
var t = (stockEl.textContent || "").toLowerCase().trim();
return t.includes("out of stock");
}
function getItemContainer(fromEl) {
// Try common bundle wrappers; fall back to something safe
return (
fromEl.closest("li") ||
fromEl.closest(".bundled_item") ||
fromEl.closest(".bundled_product") ||
fromEl.closest(".cart") ||
fromEl.parentElement
);
}
function setQtyToZero(container) {
// Catch *any* number inputs inside the container (qty boxes)
container.querySelectorAll('input[type="number"], input.qty').forEach(function (inp) {
inp.value = 0;
inp.dispatchEvent(new Event("change", { bubbles: true }));
inp.dispatchEvent(new Event("input", { bubbles: true }));
});
}
function disableContainer(container) {
container.classList.add("gb-oos");
container.style.opacity = "0.4";
// Disable everything interactive inside
container.querySelectorAll("input, select, textarea, button").forEach(function (el) {
el.disabled = true;
el.setAttribute("aria-disabled", "true");
el.style.pointerEvents = "none";
});
// Kill links too
container.querySelectorAll("a").forEach(function (a) {
a.setAttribute("tabindex", "-1");
a.setAttribute("aria-disabled", "true");
a.style.pointerEvents = "none";
a.style.cursor = "not-allowed";
});
setQtyToZero(container);
}
function enableContainer(container) {
container.classList.remove("gb-oos");
container.style.opacity = "1";
container.querySelectorAll("input, select, textarea, button").forEach(function (el) {
el.disabled = false;
el.removeAttribute("aria-disabled");
el.style.pointerEvents = "";
});
container.querySelectorAll("a").forEach(function (a) {
a.removeAttribute("tabindex");
a.removeAttribute("aria-disabled");
a.style.pointerEvents = "";
a.style.cursor = "";
});
}
function update() {
// IMPORTANT: This targets bundle item "cart" blocks like the ones you saw in DevTools:
//
document.querySelectorAll('.cart[data-bundle_id="2577"]').forEach(function (cartEl) {
var stockEl = cartEl.querySelector(".stock");
var container = getItemContainer(cartEl);
if (!container) return;
if (isOutOfStock(stockEl)) {
disableContainer(container);
} else {
enableContainer(container);
}
});
}
update();
// Bundles update via AJAX; keep re-checking
var obs = new MutationObserver(function () { update(); });
obs.observe(document.body, { childList: true, subtree: true });
});