Shae
Shae

Reputation: 319

WooCommerce: Adding category description to single product page

I've tried adding <?php do_action('woocommerce_archive_description'); ?> to content-single-product.php template file, but it's not showing up.

Is there any way to add the WooCommerce category description to single product page?

Upvotes: 1

Views: 1674

Answers (2)

Swapnali
Swapnali

Reputation: 1299

You can use this code to display the product category description to single product page -

<?php global $post, $product;
$categ = $product->get_categories();
$term = get_term_by ( 'name' , strip_tags($categ), 'product_cat' );
echo $term->description; ?>

Upvotes: 0

Shae
Shae

Reputation: 319

To add category description to single product page, using content-single-product.php template file, this code did the trick:

<?php 

    global $post;
    $args = array( 'taxonomy' => 'product_cat',);
    $terms = wp_get_post_terms($post->ID,'product_cat', $args);
    $count = count($terms); 
    if ($count > 0) {
        foreach ($terms as $term) {
            echo '<div>';
            echo $term->description;
            echo '</div>';
        }
    }

?>   

Upvotes: 3

Related Questions