Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 12, 2021 13:53
Show Gist options
  • Select an option

  • Save jorpdesigns/6a22451afee8c18585e19cfec260a563 to your computer and use it in GitHub Desktop.

Select an option

Save jorpdesigns/6a22451afee8c18585e19cfec260a563 to your computer and use it in GitHub Desktop.
Snippet to hide category on WooCommerce Shop page
<?php
add_filter( 'get_terms', 'get_custom_category_terms', 10, 3 );
function get_custom_category_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
$hide_category = array( 217 ); // Ids of the category you don't want to display on the shop page
if ( in_array( 'product_cat', $taxonomies ) && !is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->term_id, $hide_category ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment