WooCommerce: How to display Category Name in single-product.php

How can I display the category name in single-product.php?

In archive-product.php the code is:

Read More
<?php woocommerce_page_title(); ?>

but what could I use to show the category name in the single-product.php that belong to the category?

Related posts

2 comments

  1. Try this :

    global $post;
    $terms = get_the_terms( $post->ID, 'product_cat' );
    foreach ($terms as $term) {
       echo $term->name .' ';
       $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ); 
    
       $image = wp_get_attachment_url( $thumbnail_id ); 
    
      echo "'{$image}'";
    }
    
  2. find in content-single-product-CATEGORYNAME.php

    woocommerce_get_template_part( 'content', 'single-product' );
    

    Change this to:

    if (is_product_category( 'CATEGORYNAME' ) {
    woocommerce_get_template_part( 'content', 'single-product-CATEGORYNAME' );
    }else{
    woocommerce_get_template_part( 'content', 'single-product' );
    }
    

Comments are closed.