WooCommerce: Hide Products @ Shop Page

A client wanted to show only featured products on the shop page. While adding featured products is very easy (just use the WooCommerce shortcode in the page content), it seems very difficult to remove the “default” product loop. Here’s what I did.

WooCommerce Remove Loop at Shop Page
WooCommerce Remove Loop at Shop Page – the old way (commenting out core code). Thankfully there’s a better solution!

PHP Snippet: Hide All Products @ WooCommerce Shop Page

Please note: “Product Catalog” > “Shop page display” must be set to “Show products” in the WordPress > Appearance > Customizer > WooCommerce admin settings. Following snippet won’t work if you only have product categories @ product page.

To hide the “No products were found matching your selection” message that shows once the Shop page has no products to show, use this other snippet.

/**
 * @snippet       Remove Product Loop @ WooCommerce Shop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' );

function bbloomer_remove_products_from_shop_page( $q ) {
	if ( ! $q->is_main_query() ) return;
	if ( ! $q->is_post_type_archive() ) return;
	if ( ! is_admin() && is_shop() ) {
		$q->set( 'post__in', array(0) );
	}
	remove_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' );
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

60 thoughts on “WooCommerce: Hide Products @ Shop Page

  1. Awesome, thanks. Being looking for this all morning!

    Well done

  2. Thanks Rodolfo for this further help. I don’k ask you the solution …. but only some tips to add product variations. The array shouldn’t be 0 but contain all product variation 🙂
    Bye Stefano

    1. Wrong post maybe?

  3. Hey,

    Thank you for the provided solution. I just want to share my solution with you and anybody else that maybe want to hide the Woocommerce notice “No products were found matching your selection.”. You can insert below line to end of your function to hide the notice without inserting the CSS to hide it.

    remove_action( 'woocommerce_no_products_found', 'wc_no_products_found' );

    1. Nice

      1. Hi Mahmood
        Is there a way to only hide the message on shops front page? It’s nice to be able to have the message in empty categories…

        Cheers

  4. Thanks Rodolfo for this code.
    Is it possible to apply this only to category and custom-taxonomy pages?

    1. Fahad, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. thank you. With you snippet, the default product list on my shop page disappeared, I then added the woo shortcode to display my own custom product list there. But the product filter does not work with woo shortcode.
    Is there any solution.
    Thank you

    1. Hello Quy, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  6. Snippet seems to no longer work. Tried on WC 3.7 – it still showed the products on the Shop page.

    1. Danny, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  7. Uau! Perfect for me!
    This was a huge tip! Thanks a lot!

    1. Great!

  8. After updating to PHP 7.2 I get the following errors.

    “Use of undefined constant ‘woocommerce_no_products_found’ – assumed ‘‘woocommerce_no_products_found’’ (this will throw an Error in a future version of PHP)”

    1. Hi Nick, I’m not sure this is linked to my snippet to be honest. Can you disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  9. Hi, I want to remove grid products from my first shop page, but I want see grid products in products category. by this snippet every grid products removed. what can I do?!

    1. Hello Shohreh, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  10. Hi Rodolfo, I need to automatically delete woocommerce products that exceed a certain time. For example, articles that have been stopped since the last 4-hour update must be deleted. Do you know how to do it?

    1. Hello Rocco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  11. whaou thanks Rodolfo for this solution….I am looking for a solution since 1 week, you saved my week….congrat

    1. Excellent 🙂

  12. Oh my god THANK YOU , I’ve been looking for a solution to this for days… this works PERFECTLY!!!

    1. Thank you Scott 🙂

  13. Hi, thanks for this snippet! And for many others I’ve found useful. What awesome work you do! 🙂

    I think I found a way around the problem Reese had earlier, but couldn’t reply to it so I’m replying in a separate thread here. The problem was for her (him?), that the infobox saying “no products matching your selection” would appear and the PHP/CSS snippet you provided did not remove it for some reason.

    Well I had the same problem and I tweaked the snippet just to see if a separate declaration would do the trick – and tadah, now it works.

    So instead of

    if ( is_shop() ) {
    echo '<style>p.woocommerce-info{display:none}</style>';
    }

    I now have

    $bool = is_shop();
    if ($bool = true) {
    echo "<style>p.woocommerce-info{display:none;}</style>";
    }

    The annoying product loop is finally gone! Thanks a million!

    1. Thank you 🙂

  14. Unfortunately shortcodes do not work after the code, I can not customize a page with page builder origin. 🙁

    1. Hey Renato, thanks so much for your comment! I guess can you not use another WP page?

  15. Hi Rodolfo,

    I’m using your solution to remove the product loop from the shop page and it works fine, but it causes an issue with the product search result page when there are no results.

    I’m using the Advanced Woo Search plugin and it works perfect except this issue. When there aren’t products found, a page with only menu and footer is returned. If I remove your code, I get the normal No products found page. But I need to keep the product loop removed.

    Any idea how to fix this behavior?

    Big thanks for your time!

    Angel

    1. Angel, thanks so much for your comment! Unfortunately this is custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  16. Doh!

    Rodolfo, the reply link is gone for me so I’ll make a “new” comment. I’m on WC 3.0.7 and WP has also been upgraded to 4.7.5..

    1. Don’t know what to say – it works on my test site. It could be your theme is customized. If you disable all plugins and switch theme to 2016, does this work?

    2. I went in and removed the code from wc-template-functions.php that was causing the fatal error when I added your snippet, activated the snippet and even ***then*** I see the “no products were found” message at the bottom of the shop when using the Bridge theme.. Changed to twenty-fourteen and it’s fine. Even with twenty-14 active though, if I have the conflicting line of code in wc-template-functions.php, your snippet provokes a fatal error: “Cannot redeclare wc_no_products_found() (previously declared in /home/twigling/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php:2363)”.

      1. Hey Reese, I did my best 🙂 At this stage I would need to take a look at your website files, which unfortunately I can’t offer in this place. Sorry 🙂

  17. OMG!! I have wasted days trying to figure this out. THANK YOU!!! I tried adding the code to hide “No products were found matching your selection” where exactly does this go?

    1. Hey Bright thanks so much for your lovely comment! You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!

  18. Dear Lord!
    Thank you very much, I spent a huge amount of time trying to get this done, until I reached your site!

    1. Muchísimas gracias Alberto! Your feedback is much appreciated 🙂

  19. Hey Rodolfo,

    I tried method #1 on the latest WC and Storefront but it doesn’t work. The products are not rendered but it also gives an info message that no products were found which is not optimal of course. I can’t find any unique class so I can hide the info element for just the shop page.

    Thanks,

    Ben

    1. Hey Ben, thanks for your feedback! I just tried the snippet on latest WC & Storefront and products get removed from the Shop page correctly.

      However, yes, you’re right, a notice appear also: “No products were found matching your selection” you could hide that with simple PHP+CSS:

      if ( is_shop() ) {
      echo '<style>p.woocommerce-info{display:none}</style';
      }
      
      

      Let me know!

      1. Hello, and thank you for the above code, I am using method one but via a Snippets plugin so as not to edit the functions.php directly (I do the same for css).

        Can you please explain where I should put the snippet I am replying to here to remove the “NO PRODUCTS WERE FOUND MATCHING YOUR SELECTION.” -message, it’s not clear to me whether it is CSS or PHP or whether I need to put it in both.

        Thank you so much for any help you can provide 🙂

        1. Hey Reese! “Method 1”, the one you should use, is purely a PHP snippet 🙂 And I’m afraid it’s not missing any brackets 🙂 Let me know

          1. Thank you, I did use method 1, I am referring to the:

            if ( is_shop() ) {
            echo '<style>p.woocommerce-info{display:none}</style';
            }

            where should I put it, as in your comment you say ” you could hide that with simple PHP+CSS” ??? and I believed the end-style tag was missing a

            >

            but I could be wrong.

            1. add this as a php snipped does not have any effect, it still says “NO PRODUCTS WERE FOUND MATCHING YOUR SELECTION.” at the bottom of the shop page, with or without the added > bracket.

              1. Gotcha 🙂 See, we’re talking about 2 different things. In this article I show how to remove the products, while you’re asking how to remove the message – which I guess it comes as a result of removing all products 😀

                I will add the fix to this in a minute (Snippet #1).

                R

      2. PS. I tried adding as php, I think your snipped is missing an end bracket > ? Anyway still didn’t work, and it doesn’t seem like it belongs as is, as css either…?

        1. Replying here because it’s getting too skinny in the other comment sub-thread.

          I added the new snippet and this is what I got: “Don’t Panic

          The code snippet you are trying to save produced a fatal error on line 13:

          Cannot redeclare wc_no_products_found() (previously declared in /home/twigling/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php:2351)
          The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

          Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.”

          I guess I would need to go find where this other declaration happened and see what it tells to do rather than /do nothing?

          1. Reese, what version of Woo are you using?

              1. That’s the WordPress version 🙂 Version of WooCommerce?

  20. Hey Rodolfo,
    I tried this based on your recommendation in the Facebook group, but it didn’t work for me. The file isn’t exactly the same anymore so it’s no longer on line 62 (or line 52 like your screenshot shows ;)) but I found it and replaced it and nothing happened. Also, my sidebar is now displaying under my products (even at full width screen). Can you give me another tip?

    Thanks,
    Fran

    1. Hey Fran, thanks for letting me know this! I’ll take a look and send you a fix soon 🙂

      1. I just updated the blog – let me know if this works for you (“Method 1”)!

  21. Hi Rodolfo,
    I have found a problem with this solution. When I implement it by commenting out the line of code as per your tutorial, I notice that this prevents any products from ever displaying on ALL OTHER Product category pages!

    It seems that commenting out this line effects how woocommerce loads products for the WHOLE site??
    Were you aware of this? Or is this just me??

    Thanks!!

    1. Anna, I appreciate your comment! You’re indeed correct, my fix was affecting all the loop/archive pages. I just made an edit, it would be great if you could let me know if this fixes it for you 🙂 Thank you!

  22. I meant the Sort order drop down. We added another condition to two of the if statements.

  23. How do we hide the line with the selection drop down? If I comment it out then go back and click on Categories nothing shows up on those pages.

    1. Scott, thanks for your query. What do you mean by “selection dropdown”? Can you show me a screenshot?

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.