I found myself in the situation where I had to give the client the possibility to hide some of their products from search, so they can manually send the product urls to their clients. The way I got around it at the time was to create a product category called Hidden and use the snippet below, which you can paste in your theme’s functions.php file.

/*-------------------------------------
  Remove hidden category products from search
---------------------------------------*/
function wpharvest_pre_get_posts( $query ) {
   if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
       $tax_query = array(
           array(
               'taxonomy' => 'product_cat',
               'field'   => 'slug',
               'terms'   => 'hidden',
               'operator' => 'NOT IN',
           ),
       );
       $query->set( 'tax_query', $tax_query );
    }
}
add_action( 'pre_get_posts', 'wpharvest_pre_get_posts' );

If you find this snippet helpful or need help with it, please leave a comment below.

Published by Dragos Micu

WooCommerce

Leave a Reply

Your email address will not be published. Required fields are marked *

como jugar ala ruleta online gangabet casino mx resena casinos de gibraltar casino sin depsito con ethereum 2025 maxbet casino ro resena tragamonedas de frutas leobet brazil casino resena arcanebet casino resena juegos gratis tragamonedas casino argentina trucos para ganar tragamonedas casinos casinos online ruleta en vivo el tesoro de gonzo siempre gana casino registrarse juego glory and britannia playjango casino dk resena es juegos slots gratis mega fortune jugar dragon s treasure gratis ganancias historicas en este semestre para enjoy punta del este blackjack por internet como ganar en el bingo en casa frenan la causa contra las casas de apuestas online de chile rolldorado casino resena naudapay casino codigo promocional y bonus code 16114 slot shack casino resena juego wild jack prime slots casino uk resena prado sitges casino bono sin depsito 50 giros gratis 2025 34615