I am currently working on a WooCommerce site.I managed to set it up,do some configuration according to my plan.Now i want to display product categories alongside each products in product catalog,and also want to display how many time the product has been sold too.

I have done some searching and found this code,which displays product categories,but i want to display category with link to it.

 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
 $parents = get_the_terms($term->parent, get_query_var('taxonomy') );

 echo "<div class='product-cat'>";
 echo "In"." "." ";
 foreach( $parents as $parent ) {
 echo $parent->name;

Please help out on this.Thanks in advance.

1 Answer 1


Try looking in the Codex for answers. You will find that get_term_link() creates links to terms.

foreach( $parents as $parent ) {
    echo get_term_link( $parent );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.