I am trying to retrieve Related Categories from product id.
Suppose I have categories like bellow.
iPhone (Parent Category)
-iPhone 3 (sub)
-iPhone 4 (sub)
-iPhone 5 (sub)
-iPhone 6 (sub)
if a Product : iPhone 4 Charger. (in iPhone 4 sub category)
How can I retrieve all above categories by the product id (iPhone 4 Charger)
as a list?
I think Step may be == (get product id) –> (get category) –> (get parent category) –> (get category list of this parent category)
I am trying below code
<?php
$parent = get_category_parents( $cat, true, ' » ' );
echo $product->get_categories( ', ', '<span>' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' );
?>
if you are using woocommerce please try this: