Home › Forums › WoodMart support forum › Parent categories being shown in shop grid
Parent categories being shown in shop grid
- This topic has 10 replies, 2 voices, and was last updated 4 years, 2 months ago by
Artem Temos.
-
AuthorPosts
-
May 6, 2021 at 3:29 pm #290212
hariskayParticipantHello, after the last update, the parent categories are being shown in the shop grid along with child categories. This was not the case before for example if parent is Fruits and child is Apple, if we selected only Apple it would appear as Apple below the product. Now it shows Fruits, Apple despite not having the Fruits parent category selected. Please provide a fix or workaround to this since stores can have a big hierarchy of categories. Thanks.
May 7, 2021 at 6:20 am #290349
Artem TemosKeymasterHello,
Could you please check how it works with some default WordPress themes like TwentyTwenty or WooCommerce Storefront to understand is it our theme issue or not?
Regards
May 7, 2021 at 9:22 am #290431
hariskayParticipantHey there,
I checked and I dont think this functionality exists in WooCommerce and its official themes by default. Eitherway, in the past it was more sensible as we had to select both parent and child category to show them both below products, now even if we select just child, parent is shown automatically despite not being selected. Please provide a fix for this as it is complicating everything for our users.
Thank you in advance
May 7, 2021 at 9:48 am #290450
Artem TemosKeymasterHello,
Could you please disable all plugins that are not related to our theme and provide us your admin access so we can check it?
Thank you in advance
May 7, 2021 at 9:54 am #290455
hariskayParticipantHello, I have attached the credentials below, I did not disable the plugins yet because there are way too many, I dont know which affect this funtionality but I can guarantee you that before updating the theme, this problem did not exist. Since I noticed it right on the last product I added before the update.
May 7, 2021 at 12:04 pm #290501
Artem TemosKeymasterWe don’t see this problem on your website. Could you please send us some screenshots and a direct link where we can see that?
May 7, 2021 at 4:59 pm #290617
hariskayParticipantHello, I attached the screenshot. As you can see that it is showing both parent and child category below the product despite I only selected child on product page while originally this wasn’t the case.
Attachments:
You must be logged in to view attached files.May 8, 2021 at 3:28 pm #290848
hariskayParticipantHello again, here is the direct link to the page where you can see the category in private section.
Thank you
May 10, 2021 at 6:21 am #291115
Artem TemosKeymasterTry to add the following PHP code snippet to the child theme functions.php file to fix this
function woodmart_product_categories() { global $product; if ( ! woodmart_get_opt( 'categories_under_title' ) ) { return; } $terms = get_the_terms( $product->get_id(), 'product_cat' ); if ( ! $terms ) { return; } $terms_array = array(); $parent = array(); $child = array(); $links = array(); foreach ( $terms as $term ) { $terms_array[ $term->term_id ] = $term; if ( ! $term->parent ) { $parent[ $term->term_id ] = $term->name; } } foreach ( $terms as $term ) { if ( $term->parent ) { unset( $parent[ $term->parent ] ); if ( array_key_exists( $term->parent, $terms_array ) ) { $child[ $term->parent ] = get_term( $term->parent )->name; } $child[ $term->term_id ] = $term->name; } } $terms = $child + $parent; foreach ( $terms as $key => $value ) { $links[] = '<a href="' . esc_url( get_term_link( $key ) ) . '" rel="tag">' . esc_html( $value ) . '</a>'; } ?> <div class="wd-product-cats<?php echo woodmart_get_old_classes( ' woodmart-product-cats' ); ?>"> <?php echo implode( ', ', $links ); // phpcs:ignore ?> </div> <?php }
May 10, 2021 at 10:08 am #291240
hariskayParticipantThe fix you provided works. Upon selecting child category only, parent category is no longer being displayed and when both parent and child are selected, it displays them correctly as it should.
Thank you for the fix, have a good day.
May 10, 2021 at 11:22 am #291263
Artem TemosKeymasterYou are welcome!
-
AuthorPosts
- You must be logged in to create new topics. Login / Register