如何显示Woocommerce类别说明

Osh*_*rib 9 php wordpress woocommerce

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

<?php echo category_description( $category_id ); ?>
Run Code Online (Sandbox Code Playgroud)

但是,我如何显示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
?>
Run Code Online (Sandbox Code Playgroud)

不过,不行.

cod*_*abs 12

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

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

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

        }

    }
Run Code Online (Sandbox Code Playgroud)

编辑最后的答案:

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

        }

    }

?>
Run Code Online (Sandbox Code Playgroud)


Mar*_*han 5

the_archive_description()当其他(更复杂的)解决方案不能满足我的目的时。

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