• I have a simple function to exclude a few categories from my Woocommerce shop page. This is the following code:

    add_filter( 'woocommerce_product_categories_widget_args', 'woo_product_cat_widget_args' );
    function woo_product_cat_widget_args( $cat_args ) {
    $cat_args['exclude'] = '12, 13';
    return $cat_args;
    }

    Which works like a charm. However, I have now added another category that I’d like to exclude with ID 22. So I tried adding that ID as well like: ’12, 13, 22′; but when I save nothing happens, the category is still there.

    So just as a test, I removed ID 13 and 22 but Category 13 doesn’t appear either. I tried clearing my web browsers cache and also another browser but still the same result.

    I am not using a cache plugin like W3 Total Cashe etc at this stage.

    Any idea on how I can resolve this? 🙂

    The URL is http://olayagallery.com/gallery/

    • This topic was modified 9 years, 6 months ago by alboome.
Viewing 1 replies (of 1 total)
  • I tried your code on a test site, and it didn’t work for me, either. Instead, try using the slugs for the categories and this code:

    
    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( 'category-slug-1', 'category-slug-2' ) ) ) {
            $new_terms[] = $term;
          }
     
        }
     
        $terms = $new_terms;
      }
     
      return $terms;
    }
    

    Just replace the “category-slug-1” and so on with the slugs for your three categories and give it a try. Note that I have WooCommerce -> Settings -> Products -> Display -> Shop Page Display set to “Show categories” on the test site where the above code worked.

Viewing 1 replies (of 1 total)

The topic ‘Woocommerce Function Not Updating’ is closed to new replies.