Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Last active March 7, 2021 00:10
Show Gist options
  • Save rynaldos-zz/a9d357b1e3791afd9bea48833ff95994 to your computer and use it in GitHub Desktop.
Save rynaldos-zz/a9d357b1e3791afd9bea48833ff95994 to your computer and use it in GitHub Desktop.
[WooCommerce] Remove categories from shop and other pages
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
// to hide from shop page, replace is_page('YOUR_PAGE_SLUG') with is_shop()
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_page('YOUR_PAGE_SLUG') ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'woo' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
// Replace "woo" with the product category slug of the category you need hidden
// Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG
@umaisbinsajjad
Copy link

If the above function is not working for you, try this snippet from Woocommerce docs:
https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/

@faizansaeed116
Copy link

If the above function is not working for you, try this snippet from Woocommerce docs:
https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/
That a Great way,
Thanks
umaisbinsajjad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment