Buy it Now button appears when item is out of stock

Solved

Buy it Now button appears when item is out of stock

jimindraws
Tourist
15 0 3

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)

jimindraws_0-1740072749534.png

 

Accepted Solution (1)

CodingFifty
Shopify Partner
901 135 164

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
    }
});

 

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com

View solution in original post

Replies 2 (2)

CodingFifty
Shopify Partner
901 135 164

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
    }
});

 

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com
jimindraws
Tourist
15 0 3

omg THANK YOU IT WORKED!! THANK YOU SO MUCH!!!!