Created
September 11, 2019 05:33
-
-
Save kartikparmar/453e0a268e1452ff955dc84cf9991cc6 to your computer and use it in GitHub Desktop.
Removing products from a particular category on the shop page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hpcs_hide_products_category_shop( $query ) { | |
$tax_query = (array) $query->get( 'tax_query' ); | |
$tax_query[] = array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => array( 'chairs' ), // Category slug here | |
'operator' => 'NOT IN' | |
); | |
$query->set( 'tax_query', $tax_query ); | |
} | |
add_action( 'woocommerce_product_query', 'hpcs_hide_products_category_shop' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment