Ajouter ce petit snippet dans le function.php du child theme !
function exclude_product_category_from_search ( $query ) {
global $wp_the_query;
if($query === $wp_the_query && $query->is_search() && !is_admin()) {
$tax_query = [];
$query->set( 'post_type', array( 'product' ) );
$tax_query[] = array(
array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => array('exclude-from-search', 'exclude-from-catalog'),
'operator' => 'NOT IN',
)
);
if ( $outofstock_term = get_term_by( 'name', 'outofstock', 'product_visibility' ) ){
$tax_query[] = array(
array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $outofstock_term->term_taxonomy_id ),
'operator' => 'NOT IN',
)
);
}
$query->set( 'tax_query', $tax_query );
}
return $query;
}
add_filter('pre_get_posts','exclude_product_category_from_search');
Vous seriez intéressé par: