Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Hide ‘Out of Stock’ Products in WooCommerce?

Hiding out-of-stock products from your shop catalog is a simple but powerful way to improve the customer experience. By showing only items that are ready to buy, you help customers avoid the frustration of seeing unavailable products and keep their focus on what they can purchase right now. This small tweak can make the shopping journey smoother and even boost your conversion rates.

Solution: How to Hide ‘Out of Stock’ Products in WooCommerce

The code provided below will display only products that are currently in stock on the shop catalog.

add_action('woocommerce_product_query', 'ts_show_only_instock_products');

function ts_show_only_instock_products($query) {
        $meta_query = $query->get('meta_query');
        $meta_query[] = array(
                'key'       => '_stock_status',
                'compare'   => '=',
                'value'     => 'instock'
        );
        $query->set('meta_query', $meta_query);
}

Output

When a customer visits your shop, all out-of-stock products in your store will now be hidden on the shop catalog and archive pages.

Hide 'Out of Stock' Products in WooCommerce

If you’re exploring more ways to improve your shop, don’t miss our earlier post! We’ve covered how to gray out ‘Out of Stock’ variations in WooCommerce, making it easier for your customers to see what’s available.


Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x