Global
Confirmed 177,030,687 +9,025 new today Deaths 3,827,737 +227 new today Recovered 161,212,521 Active: 11,990,429 Last updated: June 15, 2021 - 9:20 am (+05:30)
Home Coding Hide particular category in woocommerce shop page

Hide particular category in woocommerce shop page

by Admin

put the code in function.php

/*** Exclude products from a particular category on the shop page*/

function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'clothing' ), // put the slugs here that you dont want to show.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}

add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Related Articles

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Decline