Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 405
Oshrib Avatar asked Oct 08 '13 13:10

Oshrib


3 Answers

$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>';

    }
}
like image 161
Prince Singh Avatar answered Oct 29 '22 17:10

Prince Singh


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; ?>
like image 38
Swapnali Avatar answered Oct 29 '22 17:10

Swapnali


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.

like image 26
MarkPraschan Avatar answered Oct 29 '22 16:10

MarkPraschan