• Resolved clickcosmo

    (@clickcosmo)


    I have been trying to hide products from a specific category from the main shop page and every code I have used it seems that its hiding the category and not the actual products! My store is set to show catalog, not to show categories. All the codes I found are showing how to hide categories if you have your shop to “Show Categories & Products” or “Show Categories”. Can anyone help?
    I have some products that I do need them to be visible in other archive pages & searches but I dont want them in the main shop page as they are only used for combo products.

    Thank you in advance!

    function prefix_custom_pre_get_posts_query( $q ) {
    	
    	if( is_shop() || is_page('shop') ) { // set conditions here
    	    $tax_query = (array) $q->get( 'tax_query' );
    	
    	    $tax_query[] = array(
    	           'taxonomy' => 'product_cat',
    	           'field'    => 'slug',
    	           'terms'    => array( 'pendants' ), // set product categories here
    	           'operator' => 'NOT IN'
    	    );
    	
    	
    	    $q->set( 'tax_query', $tax_query );
    	}
    }
    add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
    
    
    add_action( 'woocommerce_product_query', 'bbloomer_hide_products_category_shop' );
       
    function bbloomer_hide_products_category_shop( $q ) {
      
        $tax_query = (array) $q->get( 'tax_query' );
      
        $tax_query[] = array(
               'taxonomy' => 'product_cat',
               'field' => 'slug',
               'terms' => array( 'jewelry' ), // Category slug here
               'operator' => 'NOT IN'
        );
      
      
        $q->set( 'tax_query', $tax_query );
      
    }
    

    These are not working for example

    • This topic was modified 4 years, 10 months ago by clickcosmo.
    • This topic was modified 4 years, 10 months ago by clickcosmo.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide products from a specific category from woocommerce shop page’ is closed to new replies.