• Resolved weby82

    (@weby82)


    Hello !!

    In product list of category, in product box, i have the name of product category, but if i have 3 category for the product, its not the good category name that it’s display. How i display only the parent category name in product box ?

    Thks !

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Daniyal Ahmed (a11n)

    (@daniyalahmedk)

    Hi there,

    Thanks for reaching out.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

    Thread Starter weby82

    (@weby82)

    ok ! thks !

    Roxy

    (@roxannestoltz)

    Hi @weby82 ,

    Thanks for reaching out!

    It isn’t immediately clear what you are trying to achieve.

    Could you perhaps share a link to an example of what it is you would like to accomplish in order for me to have a better understanding?

    Thanks!

    Thread Starter weby82

    (@weby82)

    Hello @roxannestoltz
    I do not have link, my website is on local.
    But in product list, in shop, i have the name of category displaying in product box with price and product name. But for one product, for exemple, i have the categories “mower”, child category “thermal mower” and potentially the category “Special offer”. And now, in product list i have the category “Special offer” which appears or “thermal mower”. But I want to show only the parent category “Mower”.

    Roxy

    (@roxannestoltz)

    Hi @weby82 ,

    Thanks for providing clarity.

    From what I understand, you would like to add subcategories to your site? i.e,

    Mower
    – Thermal mower
    – – Special offer

    If this is what you are looking to achieve it can be done within your categories and product settings. Please see the guides below:

    https://www.youtube.com/watch?v=S56lvu6XUN4

    https://www.businessbloomer.com/woocommerce-categories/

    Please let me know how this goes!

    Thread Starter weby82

    (@weby82)

    No. just in product list, i need to display parent product category name for each product instead of child category name.

    Roxy

    (@roxannestoltz)

    Hi @weby82 ,

    Please see if the resolution in the thread below works for you:

    https://www.ads-software.com/support/topic/display-parent-product-category/

    Hope this helps!

    Hi @weby82

    Just for your information, apart from the development related support channels shared above, you may also be able to find someone willing to volunteer their time and knowledge in the free PHP support forum at PHP Builder.

    Thanks

    Thread Starter weby82

    (@weby82)

    Ok, I searched everywhere and by recovering pieces of code I was able to make a hook adapted to my Flatsome theme. But I think the part to recover the parent can be useful to others.

    function flatsome_woocommerce_shop_custom_category() {
    		if ( ! flatsome_option( 'product_box_category' ) ) {
    			return;
    		} ?>
    			<p class="category uppercase is-smaller no-text-overflow product-cat op-7">
    		<?php
    			global $product;
    			$curr_cat = get_queried_object();
    			if($curr_cat->parent > 0):
    				$parentcats = get_ancestors($curr_cat->term_id, 'product_cat');
    				foreach($parentcats as $parent):
    					$cat = get_term($parent,'product_cat');
    					$cat_name = $cat->name;
    				endforeach;
    			else:
    				$cat_name = $curr_cat->name;
    			endif;
    	
    			echo $cat_name;
    		?>
    		</p>
    	<?php
    	}
    
    // I cancel the addition of the category of the woocomerce function of the parent theme
    add_action( 'woocommerce_init', function(){
    	remove_action( 'woocommerce_shop_loop_item_title', 'flatsome_woocommerce_shop_loop_category', 0 );
    } );
    
    // I add my function instead
    
    add_action( 'woocommerce_shop_loop_item_title', 'flatsome_woocommerce_shop_custom_category', 0 );
    ?>

    Hi @weby82

    Awesome! Thanks for sharing the fix that worked in your case. It’ll be helpful for others having a similar requirement.

    I’ll go ahead and mark this thread as resolved. If you have any other questions related to core WooCommerce, feel free to create a new topic.

    Thread Starter weby82

    (@weby82)

    you’re welcome.

    thks !

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Show parent category name in archive product list’ is closed to new replies.