I am looking for category URL on the product detail page. I am using below code to get category ID but I am not sure how to get category URL.
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
echo $product_cat_id = $term->term_id;
break;
}
If you have the product category id
you can use
$link = get_term_link( $product_cat_id, 'product_cat' );
To get the url of the product category.
edit be sure that the product_cat_id is an integer, use the following line to be completely save:
$link = get_term_link( (int)$product_cat_id, 'product_cat' );