Created
July 12, 2021 13:53
-
-
Save jorpdesigns/6a22451afee8c18585e19cfec260a563 to your computer and use it in GitHub Desktop.
Snippet to hide category on WooCommerce Shop page
This file contains hidden or 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 | |
| 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