如何显示Woocommerce类别描述


How to display Woocommerce category description

我有常规的wordpress代码来显示类别描述:

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

但是如何显示Woocommerce类别描述呢?@@在其中一个评论建议之后,我补充说:

                    <?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
?>

不过,不是工作。

$args = array( 'taxonomy' => 'product_cat' );
$terms = get_terms('product_cat', $args);
$count = count($terms); 
if ($count > 0) {
   foreach ($terms as $term) {
        echo $term->description;
   }
}

编辑最后一个答案:

<?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>';
    }
}
the_archive_description()

我的目的工作,而其他(更复杂的)解决方案则无法实现。

如果需要,可以添加可选的前后字符串参数。

您可以显示产品类别描述 -

使用此代码 -

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

由于某种原因,主要答案为我显示了不止一个描述。

下面的答案为有相同问题的任何人解决了这个问题:

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