woocommerce是在wordpress基础上开发的,有些函数是通用的,有些需要自己调用,比如文章分类用category_description()就可以调用,而woocommerce的产品分类描述可能需要用下面的代码才能显示出来
<?php $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 //show category description $term_object = get_queried_object(); ?> <div class="woocommerce-category-description"> <div class="title"><?php echo $term_object->name; ?></div> <div class="description"><?php echo $term_object->description; ?></div> </div>
参考资料https://davidnash.com.au/woocommerce-category-description/