New Landing How can we help? Themeforest Theme Support Dante Remove one product category from the woocommerce shop page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Posted in: Dante
  • #98713
    chilledwine
    Member
    Post count: 9

    Hey guys,

    How can i remove one product category from the shop page. For these products i would like to have a separate page, using the swift page builder.

    Is that possible?

    Thanks in advance.

    #98733
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please add given below code at functions.php of child theme and activate child theme.

    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( 'your_category_slug'), 
    // Please must change category slug
    			'operator' => 'NOT IN'
    		)));
    	
    	}
     
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
     
    }

    Thanks 🙂
    With Best Regards
    Mohammad

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register