• Resolved criss.ong

    (@crissong)


    Hi,

    is there anyway to exclude all product from a category from displaying in the search?

    regards
    criss

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Damian Góra

    (@damian-gora)

    Hi,

    Paste following code into your functions.php in the child theme. Replace the term’clothing’ to your term.

    
    function exclude_terms_from_ajax_search($args)
    {
    
        $args['tax_query'][] = array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array('clothing'), // Don't display products in the clothing category on the shop page.
            'operator' => 'NOT IN'
        );
    
       return $args;
    
    }
    
    add_filter('dgwt_wcas_products_args', 'exclude_terms_from_ajax_search');
    
    Thread Starter criss.ong

    (@crissong)

    Hi,

    The product does not display in the ajax search. But if i press entered. It still redirect to the product page? Is there any fix to it?

    It should display, no product found for the exclude products in the category

    Plugin Author Damian Góra

    (@damian-gora)

    Hi,
    In this case you need an additional filter: dgwt_wcas_products_search_page_args.

    Try following code:

    
    function exclude_terms_from_ajax_search($args)
    {
    
        $args['tax_query'][] = array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array('clothing'), // Don't display products in the clothing category on the shop page.
            'operator' => 'NOT IN'
        );
    
       return $args;
    
    }
    
    add_filter('dgwt_wcas_products_args', 'exclude_terms_from_ajax_search');
    add_filter('dgwt_wcas_products_search_page_args', 'exclude_terms_from_ajax_search');
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude category from search’ is closed to new replies.