• Resolved tunyk

    (@tunyk)


    I need to hide (not disable, the category link should open as usual) certain categories in the list of categories and subcategories:

    1. If there are no products in this category
    2. If all products in this category are Out of stock
    3. If all products in this category are Catalog visibility: Hidden

    I found a solution for this for the main store page, however, on the product category and archive counters, this solution completely removes all subcategories.

    function hide_empty_categories( $terms, $taxonomies, $args ) {
    $new_terms = array();
    
    foreach ( $terms as $key => $term ) {
    
    if ( is_object( $term ) ) {
    
    if ( $term->count > 0 ) {
    $new_terms[] = $term;
    }
    }
    }
    
    return $new_terms;
    }
    
    add_filter( 'get_terms', 'hide_empty_categories', 10, 3 );
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Zubair Zahid (woo-hc)

    (@doublezed2)

    Hello tunyk,

    Thank you for reaching out to WooCommerce support.

    Your request involves custom functionality, which goes beyond general support and into specific code customization. As per WooCommerce Support Policy, we do not provide custom code solutions.

    However, I understand this is an important feature for your online store, and I would recommend consulting with a professional web developer who can provide the required coding to meet your specific needs.

    A great place to find experienced WooCommerce developers is?https://codeable.io. Codeable specializes in WordPress-based solutions, and their developers are adept at creating custom code that works well with WooCommerce.

    Thank you for understanding, and if you need further assistance with your store setup within our support scope, please feel free to ask. ??

    Best regards.

    Thread Starter tunyk

    (@tunyk)

    This issue is resolved in the categories widget in the sidebar. There is even a standard option for this – Hide empty categories (when using it, categories with no products are hidden, where all products with product_visibility = exclude-from-catalog and if all products in the category are out of stock (and the option – Hide is activated in the settings products from the catalog are out of stock).

    If I’m not mistaken, this is the branch where it was introduced https://github.com/woocommerce/woocommerce/issues/25375

    However, what I’m writing about is not about the widget, but about the display of categories and subcategories on the store’s main page, archive (category) pages.

    What I reported can be considered a bug in the plugin, because it is fixed in the widgets, but not in the places I’m talking about

    Plugin Support Zubair Zahid (woo-hc)

    (@doublezed2)

    Hello tunyk,

    Thank you for your reply.

    Before proceeding, I would like to confirm if your goal is to hide empty categories from the Shop and the Category archive pages. Is that correct?

    Additionally, the GitHub link you mentioned is about a bug that includes out-of-stock products in total category counts. I do not think this is related to your current issue.

    To provide more accurate assistance, could you please send me a copy of your site’s System Status Report? This report can greatly help us to debug the problem more efficiently.

    Here’s how you can obtain it:
    1. Navigate to WooCommerce > Status within your WordPress dashboard.
    2. Click on the ‘Get system report’ button.
    3. Then click on the ‘Copy for support’ option.

    Once you have copied the report, please paste the text into a new Gist at?https://gist.github.com. After you create the Gist, please paste the Gist link back here in your reply.

    This will allow us to review your setup in detail and provide specific guidance based on your site’s environment.

    Looking forward to your response ??

    Best regards.

    Thread Starter tunyk

    (@tunyk)

    It seems that I understood the problem, the problem with non-standard display of categories.

    For example, displaying product categories through Elementor, namely the WooCommerce Product Categories widget. With this display of categories, the option to hide empty categories hides only categories where there are no products at all, but for some reason ignores categories where all categories are out of stock and Catalog visibility: Hidden

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @tunyk,

    As far as I know, the WooCommerce Product Categories widget in Elementor is designed to hide only those categories where there are no products at all. It doesn’t consider whether products are in stock or not, or whether the Catalog visibility is set to Hidden. More info: https://elementor.com/help/woocommerce-product-categories-pro/

    This is the default behavior of the widget. If you want to hide categories where all products are out of stock, or where Catalog visibility is set to Hidden, you may need to customize the widget or use additional plugins that provide such functionality.

    Additionally, since Elementor is a third-party plugin which we don’t provide support for (please see our Support Policy), it would be best to reach out to the plugin’s developers for further assistance. I am sure they will have no problem supporting you there.

    I hope this clarifies your concern. If you have any other questions, feel free to ask.

    Hey @tunyk, it seems like our Widget Options plugin could assist you in your product categories further.

    Widget Options enables you to take full control of your widget and block visibility.

    Whether you’re using classic widgets or Gutenberg widgets and blocks, Widget Options gives your site superpowers to finely tune the widget and block visibility, formatting, and behavior based on specific criteria such as:

    1. Pages, posts, categories, tags, and URLs
    2. Devices (desktop, tablet, mobile)
    3. User roles (admin, author, subscriber, etc.)
    4. User logged-in status
    5. Days of the week (and dates)
      and much more!

    I hope this info. helps.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to hide certain categories on the main page of the store, on the pages of ca’ is closed to new replies.