For one of my projects, I use WooCommerce product shortcodes to pull specific categories to the homepage. One issue I’ve had for a while has been that shortcodes on their own, do not give you the ability to exclude sold out items, so where I am pulling four items to a homepage and half of them show as sold out, it provides little to no value to the users.

I recently found a very useful post on the support page for the WooCommerce plugin where a plugin contributor provides a way to exclude sold out items.

Essentially, what you do is create a class to exclude these by simply adding the following code to your functions.php file (be sure to backup before you make any changes to your functions.php file)

Once you’ve added this code, you can then edit your shortcode to include class=”outofstock”.

An example would be, using a shortcode to display four featured products at random but exclude sold out items. Your shortcode would look something like this:

[featured_products limit=”4″ columns=”4″ orderby=”rand” class=”outofstock”]

Was this article helpful?