How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: Hide Out of Stock Products from Homepage in WooCommerce (Keep Them Visible Elsewhere)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Learn > Web Development > Hide Out of Stock Products from Homepage in WooCommerce (Keep Them Visible Elsewhere)
Web Development

Hide Out of Stock Products from Homepage in WooCommerce (Keep Them Visible Elsewhere)

how7o
By how7o
Last updated: January 13, 2026
5 Min Read
WooCommerce homepage filter to hide out of stock products
SHARE

I noticed something that was quietly killing my store’s first impression: my homepage product sections were full of Out of stock items. It looked messy, and honestly, it felt like I was advertising products people couldn’t buy.

Contents
  • Best solution: hide out-of-stock products only on the homepage (code method)
    • Step 1: Add this code to your site
    • Step 2: Clear cache (if you use caching)
    • Step 3: Test it properly
  • If you’re using WooCommerce Blocks (no code option)
  • Why I didn’t use the global “Hide out of stock items” setting
  • Common issues (quick fixes)
    • It doesn’t work on my homepage
    • Changes don’t show up
  • Final thoughts

I already knew WooCommerce has a setting to hide out-of-stock products globally (WooCommerce → Settings → Products → Inventory). But that wasn’t what I wanted. I still wanted out-of-stock items to remain visible on category pages and search (for SEO, browsing, and “notify me” type shoppers). I only wanted the homepage to stay clean.

Here’s what worked for me: I filtered WooCommerce product queries only on the homepage so anything with _stock_status = outofstock disappears from homepage grids, while everything stays visible everywhere else.

Hide out of stock products on WooCommerce homepage

Best solution: hide out-of-stock products only on the homepage (code method)

This method is perfect if your homepage shows products using WooCommerce blocks, shortcodes, or theme sections that use WooCommerce’s product query system.

Before you edit anything: If you can, use a child theme (or a Code Snippets plugin) so theme updates don’t overwrite your changes.

Step 1: Add this code to your site

Add the following code to functions.php in your child theme, or paste it into a snippets plugin:

add_filter( 'woocommerce_product_query_meta_query', function ( $meta_query ) {

    // Run only on the homepage/front page
    if ( is_front_page() || is_home() ) {

        // Show ONLY in-stock products on homepage
        $meta_query[] = array(
            'key'     => '_stock_status',
            'value'   => 'instock',
            'compare' => '='
        );

        /**
         * OPTIONAL:
         * If you want to show backorders too, replace the block above with:
         *
         * $meta_query[] = array(
         *     'key'     => '_stock_status',
         *     'value'   => array( 'instock', 'onbackorder' ),
         *     'compare' => 'IN'
         * );
         */
    }

    return $meta_query;

}, 20 );

That’s it. This tells WooCommerce: “When we’re on the homepage, only fetch products that are in stock.” On category pages, search results, and product pages, nothing changes.

Step 2: Clear cache (if you use caching)

If your homepage is cached (very common), you won’t see changes immediately. Clear your cache from:

  • Your caching plugin (LiteSpeed Cache / WP Rocket / etc.)
  • Server cache (if your host provides one)
  • CDN cache (Cloudflare, etc.)

Step 3: Test it properly

  • Pick a product that appears on the homepage
  • Mark it Out of stock in WooCommerce
  • Refresh the homepage — it should disappear
  • Open its category page or search — it should still be visible there

If you’re using WooCommerce Blocks (no code option)

If your homepage is built with the WooCommerce “Products” block (or a similar product grid block), some setups let you filter by Stock status directly in the block settings. If you see an option like “Stock status” or “In stock only,” enable it for homepage blocks.

This is the easiest method when available — but not every theme/block combination exposes the setting. If you can’t find it, the code method above is the most reliable.

Why I didn’t use the global “Hide out of stock items” setting

WooCommerce has a built-in setting to hide out-of-stock products from the entire catalog. That’s fine for some stores, but in my case it caused problems:

  • I still wanted out-of-stock items visible in categories (for SEO + browsing)
  • I didn’t want old product links to feel “missing”
  • I wanted customers to see the product page (and maybe join a waitlist)

So filtering only the homepage gave me the best of both worlds: clean storefront + full catalog visibility.

Common issues (quick fixes)

It doesn’t work on my homepage

  • Your homepage may be using a custom query that doesn’t use WooCommerce’s product query system.
  • Try switching the homepage section to a WooCommerce Products block/shortcode, or tell me what theme/page builder you’re using and I’ll tailor the fix.

Changes don’t show up

  • Clear cache (plugin + server + CDN)
  • Try a private/incognito window
  • Temporarily disable homepage cache to confirm the logic works

Final thoughts

Hiding out-of-stock products from the homepage made my store look instantly cleaner. Customers stop seeing “Out of stock” everywhere, and my homepage feels like a curated selection again — while my categories and search still show the full catalog.

TAGGED:functions.phpOut of StockphpStock ManagementStore OptimizationWooCommerceWooCommerce Blockswordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Check if Laravel scheduler is running (cron + php artisan schedule:run) How to Check if Laravel Scheduler Is Running (Cron + Logs)
Next Article Login to Laravel programmatically without a password (Auth::login and loginUsingId) Login to Laravel Programmatically Without a Password (Auth::login & loginUsingId)
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

WordPress check if user is logged in with is_user_logged_in()
Web Development

How to Check If a User Is Logged In in WordPress

7 Min Read
WordPress login user programmatically — wp_set_current_user plus wp_set_auth_cookie
Web Development

How to Login a User Programmatically in WordPress

8 Min Read
Laravel Vite combine CSS — @import chain bundles vendor and app stylesheets
Web Development

How to Compile Multiple CSS into One CSS with Laravel + Vite

7 Min Read
WooCommerce orders as My Account default — menu filter + redirect
Web Development

How to Display Orders Instead of Dashboard on the WooCommerce My Account Page

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?