mercredi 25 février 2015

Get only one product category woocommerce


I have to get and show only one category name from a product. I have almost read everything and tried everything.



<?php
$term = get_the_terms( $post->ID, 'product_cat' );
foreach ($term as $t) {
$parentId = $t->all;
if($parentId == 0){
echo $t->name;
}else{
$term = get_terms( 'product_cat', array('include' => array($parentId)) );
}
}

?>


It shows one long string with all the category names. How should I get only one category and show its name. You guys are my last chance. Thank you in advance.





Aucun commentaire:

Enregistrer un commentaire