Need to filter woocommerce search results

This topic has 2 replies, 2 voices, and was last updated 8 years, 4 months ago ago by Brian Johnson

  • Avatar: QuidProject
    QuidProject
    Participant
    November 24, 2015 at 18:31

    Hello,
    i need to filter the results of product text search to be limited to the products that are in a specific category!
    I already did something really similar, to display everywhere in my site only products that have a specific category.

    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_product_category() || is_product_tag() || is_product_taxonomy() || is_filtered() || is_search() ) ) {
    
    		$q->set( 'tax_query', array(array(
    			'taxonomy' => 'product_cat',
    			'field' => 'slug',
    			'terms' => array( 'web' ), // Display only products in the "web" category on the shop page
    			'operator' => 'IN'
    		)));
    		
    		
    	
    	}
    
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    Now i need something similar to work both on the search result archive page, (i added is_search() but turns out it only works for normal wordpress search result pages), and for the ajax search too…

    Even if you can only point me in the right direction i would appreciate.

    Thank You.

    1 Answer
    Avatar: Brian Johnson
    Brian Johnson
    Member
    November 25, 2015 at 15:32

    Hello

    Sorry . The modification you asked to do requires additional customization which lays beyond the scope of our basic support.

    Regards,
    Brian Johnson

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.