Last active
November 29, 2018 17:19
-
-
Save jrick1229/98fee7a4ff3ceef2b20c708b408f2e0e to your computer and use it in GitHub Desktop.
Hide products by category from the shop page
This file contains 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 | |
/** | |
* Exclude products from a particular category on the shop page | |
*/ | |
function wcs_hide_unwanted_category( $q ) { | |
$tax_query = (array) $q->get( 'tax_query' ); | |
$tax_query[] = array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => array( 'not-displayed' ), // Don't display products in the clothing category on the shop page. | |
'operator' => 'NOT IN' | |
); | |
$q->set( 'tax_query', $tax_query ); | |
} | |
add_action( 'woocommerce_product_query', 'wcs_hide_unwanted_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment