Oshrib
Oshrib

Reputation: 1900

How to display Woocommerce category description

I have the regular wordpress code to display category description:

<?php echo category_description( $category_id ); ?>

But how can i display Woocommerce category description? @@ After one of the comment suggestion i added:

                    <?php 
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post(); 
global $post, $product; $categ = $product->get_categories(); $term = get_term_by ( 'name' , strip_tags($categ), 'product_cat' ); echo $term->description; 
        } // end while
    } // end if
?>

Still, not work.

Upvotes: 9

Views: 58954

Answers (4)

Prince Singh
Prince Singh

Reputation: 5183

$args = array( 'taxonomy' => 'product_cat' );
$terms = get_terms('product_cat', $args);

$count = count($terms); 
if ($count > 0) {

   foreach ($terms as $term) {
        echo $term->description;
   }
}

Edit for Last answer:

<?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 style="direction:rtl;">';
        echo $term->description;
        echo '</div>';

    }
}

Upvotes: 16

MarkPraschan
MarkPraschan

Reputation: 600

the_archive_description() worked for my purposes when other (more complicated) solutions would not.

Optional before and after string parameters can be added if needed.

Upvotes: 5

user2703913
user2703913

Reputation: 121

The main answer for some reason displayed more than one description for me.

The answer below solved this for anyone with the same issue:

https://stackoverflow.com/a/19266706/2703913

Upvotes: 0

Swapnali
Swapnali

Reputation: 1299

You can display the product category description -

use this code -

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

Upvotes: 3

Related Questions