• Resolved meerulz

    (@meerulz)


    Hello and thanks for the nice plugin.
    we have had some unnecessary list of categories showing on Shop Page, we hide most of them through plugin, now the problem is when we click on some category link and that page opens, it shows all the categories again, we don’t want that. for example if you click Apparel> and Apparel page loads, it will show you again all the categories on the list which were hidden on shop page. can some one please help us.
    thank you so very much in advanced.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi @meerulz,

    try this code in functions.php in child theme changing uncategorized with your vategory slug name .

    //hide determinate category
    add_filter( 'get_terms', 'cosmoweb_exclude_category', 10, 3 );
    function cosmoweb_exclude_category( $terms, $taxonomies, $args ) {
      $new_terms = array();
      // if a product category and on a page
      if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_page() ) {
        foreach ( $terms as $key => $term ) {
    // Enter the name of the category you want to exclude in place of 'uncategorised'
          if ( ! in_array( $term->slug, array( 'uncategorized' ) ) ) {
            $new_terms[] = $term;
          }
        }
        $terms = $new_terms;
      }
      return $terms;
    }
    Thread Starter meerulz

    (@meerulz)

    Hello @cosmoweb
    thank you for your reply,
    1- i don’t have a child theme so i put this code in snippet and saved it.
    but it didn’t work.

    2- and is that the correct way to add multiple categories.
    if ( ! in_array( $term->slug, array( 'apparel,automotive' ) ) ) {

    Thread Starter meerulz

    (@meerulz)

    Can someone help please?

    Plugin Contributor James Koster

    (@jameskoster)

    we have had some unnecessary list of categories showing on Shop Page, we hide most of them through plugin

    Sounds like the plugin might need updating to accommodate this scenario.

    I’m curious why you have categories that you want to hide, though? What’s the use case here?

    James
    Designer @ Automattic

    Thread Starter meerulz

    (@meerulz)

    @jameskoster we don’t want to clutter our All Products(shop) page, we are showing some categories in different section of our website, so we don’t want all products to show at one place and then repeat on second section. thats why we want to hide some categories because we are showing that categories on different pages.
    i hope you are getting my point.
    plugin we are using is “Hide WooCommerce Categories On Shop Page”
    thank you for your time and support. appreciate it.

    • This reply was modified 6 years, 3 months ago by meerulz.
    Plugin Contributor James Koster

    (@jameskoster)

    I see.

    I wouldn’t normally recommend this, but honestly the simplest solution here would be to edit the plugin to accommodate you requirement. In fact there’s a guide on how to do this on the plugin listing here.

    You’d just need to modify this part;

    is_page('YOUR_PAGE_SLUG')

    To this;

    is_shop()

    I believe that should work, but I haven’t tested it. Let me know ??

    If you do this I’d also suggest changing the plugin name etc to something custom. That way you won’t forget about your changes and accidentally overwrite your changes if/when an update to the original plugin is released.

    EDIT: Looking at @cosmoweb’s snippet, I believe that would work if you changed is_page() to is_shop().

    James
    Designer @ Automattic

    • This reply was modified 6 years, 3 months ago by James Koster.
    • This reply was modified 6 years, 3 months ago by James Koster.
    Thread Starter meerulz

    (@meerulz)

    Thank you @jameskoster for taking out time for my thread, i have tried all but its not working for me, i don’t know if i am doing right or not.
    after replacing is page to is shop. its still the same.
    have a look at attached image link

    View post on imgur.com

    do you have any other solution, we can get rid of plugin, all we need is hide some categories on main shop page and inside pages as well.
    thanks.

    As near as I can tell by the screenshot, what you are saying is that you don’t expect the product categories to be displayed in the product category widget. If I am correct in that assumption, then you will also need custom code to remove those “hidden” product categories from the widget.

    The filter that can be used to conditionally remove categories is named woocommerce_product_categories_widget_args and can be seen in code here: https://github.com/woocommerce/woocommerce/blob/3.5.2/includes/widgets/class-wc-widget-product-categories.php#L288

    There is an example of how that filter can be used to exclude product categories here: https://www.ads-software.com/support/topic/exclude-category-from-product-categories-widget/

    Kind regards,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Hide Categories on Shop and Inside pages’ is closed to new replies.