Woocommerce shop page by default display products of all categories. But, if you want to hide products from a particular category on the shop page then you have to follow the steps given below and make modifications in your WooCommerce theme.
To remove products from a particular product category on the WooCommerce shop page you need to add the following lines of code in your theme's functions.php
file. Just append the following lines of code at the bottom of functions.php
/**
* Remove specific category ID's from the WooCommerce shop page
*/
add_action( 'pre_get_posts', 'magik_remove_product_cats_shop_page');
function magik_remove_product_cats_shop_page( $qry ) {
// Comment out the line below to hide products in the admin as well
if ( is_admin() ) return;
if ( is_shop() && $qry->is_main_query() ) {
$qry->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'ID',
'terms' => array( 93),
'operator' => 'NOT IN'
)
) );
}
}
If you face any problems or need our professional services, please email us at [email protected]
Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.