Shopify themes, liquid, logos, and UX
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)
Solved! Go to the solution
This is an accepted solution.
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
}
});
This is an accepted solution.
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!!!!
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025