Hello I have a couple of items that I have set the inventory to 0 or less than 0, but the “Buy it Now” button still appears on the product page. You can see that the item is marked as sold out and the “add to cart” button changes to “sold out” but the “buy it now button” is still there. The “buy it now” button doesn’t do anything when you click on it. How do fix this so that “buy it now” button only appears when the product inventory is greater than 0? (www.jimindraws.com)
Hi @jimindraws ,
Go to Online Store, then Theme, and select Edit Code.
Search for global.js file Add the provided code at the end of the file.
document.addEventListener("DOMContentLoaded", function () {
// Check if product is out of stock
var buyNowButton = document.querySelector(".shopify-payment-button");
var soldOutButton = document.querySelector(".product-form__buttons .button[disabled]");
if (buyNowButton && soldOutButton) {
buyNowButton.style.display = "none"; // Hide Buy It Now button
}
});
omg THANK YOU IT WORKED!! THANK YOU SO MUCH!!!
1 Like