Categories for hidden products display on shop page

This topic has 7 replies, 3 voices, and was last updated 1 weeks, 2 days ago ago by Andrew Mitchell

  • Avatar: kikjou
    Martin
    Participant
    April 22, 2024 at 15:38

    Hi,

    I have some products hidden from shop and search that cause their corresponding categories to show up on the shop page. Is it possible to remove that behaviour? Those categories are otherwise empty and do not contain visible products.

    Thank you
    Best regards
    Martin

    Content is visible for topic creator and
    support staff only.
    6 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 22, 2024 at 15:53

    Hello, Martin,

    Thank you for reaching out to us with your query.

    Please provide temporary wp-admin and FTP access. We will check what can be done to help you.

    To grant WP-Admin access, please proceed to create a new user account with an administrator role through your WordPress Dashboard. Once the account is established, you may securely transmit the username and password to us via the Private Content section designated for this purpose.

    For FTP access, we require the following details: FTP host, FTP username, FTP password, FTP port, and FTP encryption type. If you need assistance in creating these credentials, please reach out to your hosting provider who will guide you through the process.

    Best Regards,
    8Theme’s Team

    Avatar: kikjou
    Martin
    Participant
    April 22, 2024 at 17:31

    Hi, pls see private content,
    thank you!
    Martin

    Content is visible for topic creator and
    support staff only.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    April 24, 2024 at 15:22

    Hello, Martin,

    I hope this message finds you well.

    We have recently added the following code to your child theme,

    add_filter( 'woocommerce_product_categories_widget_args', 'filter_product_categories_widget_args', 10, 1 );
    function filter_product_categories_widget_args( $args ) {
        $args['hide_empty'] = true; // This hides categories without posts by default, but we need to ensure it considers visibility.
    
        return $args;
    }
    
    add_filter('get_terms', 'hide_empty_categories', 10, 3);
    function hide_empty_categories($terms, $taxonomies, $args) {
        $new_terms = array();
        if (in_array('product_cat', (array) $taxonomies) && !is_admin() && is_shop()) {
            foreach ($terms as $key => $term) {
                if (category_has_visible_products($term)) {
                    $new_terms[] = $term;
                }
            }
            $terms = $new_terms;
        }
        return $terms;
    }
    
    function category_has_visible_products($term) {
        $args = array(
            'post_type'      => 'product',
            'post_status'    => 'publish',
            'posts_per_page' => -1,
            'fields'         => 'ids',
            'tax_query'      => array(
                array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'id',
                    'terms'    => $term->term_id,
                ),
            ),
            'meta_query'     => array(
                array(
                    'key'     => '_visibility',
                    'value'   => array('catalog', 'visible'),
                    'compare' => 'IN'
                )
            )
        );
        $query = new WP_Query($args);
        return $query->have_posts();
    }

    which successfully hid some categories. However, it appears that the categories ‘Sträucher’ and ‘Beerenobst’ were not affected. There might be an issue with the products in these categories.

    Could you please re-save these products? If the categories still do not disappear after this action, kindly send us the links to these products so we can further investigate the issue.

    Thank you for your attention to this matter. We look forward to your prompt response.

    Best Regards,
    8Theme’s Team

    Avatar: kikjou
    Martin
    Participant
    April 25, 2024 at 08:43

    Hello Andrew,

    thank you very much for quick help! Re-saving the product did remove the categories.

    I guess, that code will be integrated in a future release of xstore, so I can remove it at some point in time?

    Best regards
    Martin

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    April 25, 2024 at 16:44

    Hello, Martin

    We hope this message finds you well. We are pleased to inform you about an upcoming update to our platform that will introduce a new feature: the “Hide categories with all hidden products” option.

    Please note that this feature will be disabled by default, as many of our clients are accustomed to the current display of categories, and for some, this arrangement is critical. Should you wish to utilize this new feature, you will need to enable the “Hide categories with all hidden products” option and remove the custom code from the child theme.

    For your convenience, here is the path to access the new option:
    Customizer -> WooCommerce (Shop) -> Shop -> Shop Page Layout -> “Hide categories with all hidden products” option.

    We trust this update will enhance your experience and streamline your operations. Should you have any questions or require further assistance, please do not hesitate to contact us.

    Best Regards,

    The 8Theme Team

    Files is visible for topic creator and
    support staff only.
    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    April 26, 2024 at 07:18

    Dear Martin,

    Choosing our theme reflects your commitment to quality, and for that, we’re genuinely grateful. As we constantly strive to elevate your experience, your feedback is an invaluable gift. Could you kindly take a moment to rate our product with 5 stars on ThemeForest?

    Click here to share your insights: https://themeforest.net/downloads

    Your support fuels our journey, and we appreciate it more than words can express.

    Best Regards,
    The 8Theme Team

  • Viewing 7 results - 1 through 7 (of 7 total)

The issue related to '‘Categories for hidden products display on shop page’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.