Skip to content

Instantly share code, notes, and snippets.

@dhirenpatel22
Created July 31, 2020 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhirenpatel22/2c0d603e66b29a0fd5bb033d6d876aa7 to your computer and use it in GitHub Desktop.
Save dhirenpatel22/2c0d603e66b29a0fd5bb033d6d876aa7 to your computer and use it in GitHub Desktop.
Exclude specific categories from the Shop page
<?php
/**
* Exclude specific categories from the Shop page
* @param $terms
* @param $taxonomies
* @param $args
* @return array
*/
function ts_get_subcategory_terms($terms, $taxonomies, $args ) {
$new_terms = array();
// if it is a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'uncategorized', 'category1' ) ) ) { //pass the slug name here
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment