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!!!!
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025