Reputation: 117
How can I display the category name in single-product.php?
In archive-product.php the code is:
<?php woocommerce_page_title(); ?>
but what could I use to show the category name in the single-product.php that belong to the category?
Upvotes: 1
Views: 7143
Reputation: 9995
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}'";
}
Upvotes: 3
Reputation: 113
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' );
}
Upvotes: 0