Last active
December 29, 2022 13:49
-
-
Save woogists/11ae5067dee442682ce2895f7b1645c2 to your computer and use it in GitHub Desktop.
[Frontend Snippets] Exclude products from a particular category on 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
/** | |
* 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' ), // 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', 'custom_pre_get_posts_query' ); |
hello, I have a Parse error: syntax error, unexpected end of file that appears after adding the function in the functions.php file.thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there also an option to hide/exclude specific product categories from the whole frontend?