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');
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
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');