I’m working on an art website that sells printed artworks with a specific print number attribute and various frame options. Each print number has only one unit in stock, and once it’s sold, that number should become unavailable.
I’ve managed to implement the functionality where the product is marked as unavailable after it’s sold. However, the issue is that the option still appears on the shop page, only disabling the "Add to Cart" button once the visitor selects that variation. This can be frustrating for users.
How can I make sold-out print numbers unclickable, blur or dissapear from the shop page entirely?
image showing my shop page product variation
on the image i attached with you print number 1 is sold but it’s still visible on the shop page.
i tried to use some code snippet but none of them worked, i will be glad if you have a plugin recommendation or custom code.
2
Answers
You can hide sold-out variations from your WooCommerce shop page by adding a custom code snippet to your theme’s functions.php file. Here’s how to do it:
}
For your scenario where you want to make specific product variations (in this case, print numbers) disappear or become unselectable on the shop page when they are sold out, you can approach it in a few different ways. Below, I’ll provide a custom solution as well as a plugin recommendation.
Option 1: Custom Code to Hide Sold-Out Variations
You can use custom JavaScript and PHP to make the sold-out variations disappear entirely or blur them out in your shop page. Here’s a custom solution for WooCommerce:
Step 1: Add a Custom PHP Function
Add the following code to your theme’s functions.php file or in a custom plugin to filter the product variations based on availability:
Step 2: Style Sold-Out Variations (Optional)
If you prefer to blur out sold-out variations instead of hiding them, you can add some custom CSS to your theme or plugin’s stylesheet:
And then modify the PHP function to add a CSS class to the sold-out variations: