This topic has 7 replies, 3 voices, and was last updated 6 months, 3 weeks ago ago by Andrew Mitchell
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
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
Hi, pls see private content,
thank you!
Martin
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
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
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
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
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