How to Hide All Products From Shop Page in WooCommerce

 Hide All Products Shop Page WooCommerceDo you want to hide all products from the shop page in your WooCommerce store? Are you running something like a B2B/wholesale or members-only store and you do not want every single product available to the public? This post will show you two methods that you can use to hide all products on the shop page.

The first one involves a developer-friendly method that involves the use of a filter and hook. The other method is built-in in the WordPress core and I will share it in this post. With all that said, let us look into the two ways you can employ to hide all WooCommerce products from the shop page.

a)    Steps to Add a PHP Snippet to Hide All Products WooCommerce Shop Page

To do this, you need to follow these simple steps.

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will add a function to hide all products at the WooCommerce shop page.
  3. Add the following code to the php file:
/**
 * @snippet Remove Product Loop @ WooCommerce Shop
*/
add_action( 'pre_get_posts', 'njengah_remove_products_from_shop_page' );

function njengah_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', 'njengah_remove_products_from_shop_page' );

}

This will be the Outcome:Removing all products in WooCommerce

  1. To remove the ‘No products were found matching your selection’ simply add this line of code at the end of the php file.
/**
* @snippet Remove "No products were found matching your selection" @ WooCommerce Loop Pages
*/

remove_action( 'woocommerce_no_products_found', 'wc_no_products_found' );
  1. This will be the outcome:remove the no products were found matching your selection

How the code works.

In the code above, the  ‘pre_get_posts‘, ‘njengah_remove_products_from_shop_page‘  action that will target the shop page. To remove the products, I created a function that will remove the products, aided by a series of loops and a remove action.

b)    Steps to hide Products from Displaying in Shop Page WooCommerce

There is nothing much to discuss this. This simple solution took me a long time to find but it will help you hide a particular product form displaying from your WooCommerce shop page but still have it published here’s the trick:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Products > All Products. This will open all the products in your WooCommerce store and you need to open the details of the product that you want to hide and click on Edit.
  3. On the right side of the screen, you will see the Catalog visibility and you need to click on edit as shown below:Catalog visibility
  4. After clicking on Edit, a set of options will appear with checkboxes which will allow you to hide the product as shown below:edit

hide products in catalog visibility You can preview the changes that you make or you can click on OK and update to publish the changes that you have made.

  1. To see the outcome you need to refresh the Shop page and that particular product will not appear on the Shop page.

It is however important to note that this will only work for particular products, not all of the products. This could be a solution if you only want to hide particular products, which you select and hide, following the simple steps above.

Conclusion

In this post, I have highlighted two methods that you can use to hide products in your WooCommerce Shop page. The first method is a developer-friendly method of using a PHP code snippet and the second one involves hiding a particular product. However, if you want to hide many products, it is much more efficient to just bulk assign them to a category and hide that category using the next method.

Similar Articles

Comments are closed.