Home Forums WoodMart support forum Parent categories being shown in shop grid

Parent categories being shown in shop grid

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #290212

    hariskay
    Participant

    Hello, 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.

    #290349

    Artem Temos
    Keymaster

    Hello,

    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

    #290431

    hariskay
    Participant

    Hey 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

    #290450

    Artem Temos
    Keymaster

    Hello,

    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

    #290455

    hariskay
    Participant

    Hello, 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.

    #290501

    Artem Temos
    Keymaster

    We don’t see this problem on your website. Could you please send us some screenshots and a direct link where we can see that?

    #290617

    hariskay
    Participant

    Hello, 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.
    #290848

    hariskay
    Participant

    Hello again, here is the direct link to the page where you can see the category in private section.

    Thank you

    #291115

    Artem Temos
    Keymaster

    Try 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
    }
    #291240

    hariskay
    Participant

    The 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.

    #291263

    Artem Temos
    Keymaster

    You are welcome!

Viewing 11 posts - 1 through 11 (of 11 total)