Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #665762

    Hey,

    I have a category that is showing up in my shop but I need to exclude it from there.

    I found this, but i dosen’t seem to woork
    https://kriesi.at/support/topic/hideexclude-a-category-from-woocommerce-shop-page/

    The reason I would like it removed is that I want to show some selected products on the front slider, but they should only be visible there.

    Hope you can help

    Regards Pete,

    #665772

    Hey,

    You can close this, i found this code – and it seems to work:

    /* Exclude Category from Shop*/
    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
      if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
        foreach ( $terms as $key => $term ) {
          if ( ! in_array( $term->slug, array( 'cat1', 'cat2' ) ) ) {
            $new_terms[] = $term;
          }
    
        }
    
        $terms = $new_terms;
      }
    
      return $terms;
    }

    Regards Pete

    • This reply was modified 8 years, 3 months ago by 2funky.
    #666134

    Hi Pete,

    Great, glad you got it working and thanks for sharing :-)

    Please open a new thread if you should have any further questions or problems.

    Regards,
    Rikard

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Hide/Exclude a category from WooCommerce Shop page’ is closed to new replies.