S
S
sagittelnerd2022-04-13 23:11:41
Taxonomy
sagittelnerd, 2022-04-13 23:11:41

How to hide a category from the entire site?

The code given below:

add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );

function get_subcategory_terms( $terms, $taxonomies, $args ) {

  $new_terms = array();

  if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {

    foreach ( $terms as $key => $term ) {

      if ( ! in_array( $term->slug, array( 'stands', 'lkmstands',', ) ) ) {
        $new_terms[] = $term;
      }

    }
    $terms = $new_terms;
  }
  return $terms;
}

Hides the category only on the store page, but how to hide it on the entire site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2022-04-14
@artzolin

To filter the term query, use the filterpre_get_terms

function wc_custom_sort_get_terms_args( $args, $taxonomies ) {
    if ( isset( $taxonomies[ 'product_cat' ] ) ) {
        $args['exclude'] = [5,6,7];
    }
 
    return $args;
}
add_filter( 'get_terms_args', 'wc_custom_sort_get_terms_args', 10, 2 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question