• Hello everybody;
    I am pretty new in e-commerce and everyday learning new things which i enjoy so much but sometimes stuck on some points so i feel need to ask you guys

    Alright i usually use inspect element and copy style and edit it in editor in wp. But i came across problem which is i try to make certain parent category invisible on shop page but when i edit style(display:none) all categories go away.

    .woocommerce ul.products li.product, .woocommerce-page ul.products li.product {
        float: left;
        margin: 0 3.8% 2.992em 0;
        padding: 0;
        position: relative;
        width: 22.05%;
    }
    .woocommerce .products ul li, .woocommerce ul.products li {
    }

    So should i edit this style to make parent category invisible?

    Thank you in advance!

Viewing 1 replies (of 1 total)
  • You shouldn’t be using CSS to do this. Try this snippet:

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
    	if ( ! $q->is_main_query() ) return;
    	if ( ! $q->is_post_type_archive() ) return;
    
    	if ( ! is_admin() && is_shop() && ! is_user_logged_in() ) {
    
    		$q->set( 'tax_query', array(array(
    			'taxonomy' => 'product_cat',
    			'field' => 'slug',
    			'terms' => array( 'color', 'flavor', 'spices', 'vanilla' ), // Don't display products in these categories on the shop page
    			'operator' => 'NOT IN'
    		)));
    
    	}
    
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    Source: WPExplorer

Viewing 1 replies (of 1 total)
  • The topic ‘Removing Parent Category From Shop Page’ is closed to new replies.