Display Category Name

Q: I want to display the direct parent category name of the current product and just the direct parent. When I search, all I can find is code that lists all the categories of that product (eg: grandparent).

A: Template code provided by the user on the Forum to display the product category:

$terms = get_the_terms( $post->ID, 'product_cat' );
$term = current($terms);
echo "<h1 class="shop-category-title">".$term->name."</h1>";

To make a list of the categories:

 $terms = get_the_terms( $post->ID, 'product_cat' );
 echo '<ul>';
 foreach ($terms as $term) {
 echo '<li><a href="'.get_term_link($term->slug, 'product_cat').'">'.$term->name.'</a></li>';
 echo '</ul>';