I have a Woocommerce product and I need to display the top level category of the category assigned to the product on this page
- Main Product Category -- Sub Product Category --- Category Assigned to product
I need to get the identifier or name "Main Product Category" so that I can display it in the category of one product.
I have already tried the following:
global $post; $terms = get_the_terms( $post->ID, 'product_cat' ); foreach ($terms as $term) { $product_cat_id = $term->term_id; $thetop_parent = woocommerce_get_term_top_most_parent( $product_cat_id , 'product_cat' ); echo $thetop_parent; }
But that didn’t work at all, and it slows down the page after loading after woocomerce_get_term ... I'm not sure what to do at this moment. It
Thanks for any help on this.
php wordpress woocommerce
Gman
source share