Woocommerce 类别说明 [英] Woocommerce category description

查看:32
本文介绍了Woocommerce 类别说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个代码:

 <?php 
 global $post;
$args = array( 'taxonomy' => 'product_cat');
$terms = get_the_terms($category->slug,'product_cat', $args);

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

        foreach ($terms as $term) {
            echo '<div style="direction:rtl;">';
            echo $term->description;
            echo '</div>';

        }

    }

?>

代码将显示类别描述.问题 - 在子类别上,它将显示子类别描述 + 父级描述.

The code will display category description. The problem - on sub-category it will display the sub-category description + the parent description.

如何单独显示描述:在父级 - 父级描述,以及在子级 - 仅子级描述?

How i can display the description separate: in parent - the parent description, and on sub - only the sub description?

推荐答案

试试这个,让我知道它是否对你有帮助

Try this and let me know if it helped you

add_action( 'woocommerce_after_subcategory_title', 'custom_add_product_description', 
12);
function custom_add_product_description ($category) {
$cat_id        =    $category->term_id;
$prod_term    =    get_term($cat_id,'product_cat');
$description=    $prod_term->description;

echo '<div>'.$description.'</div>';
}

这篇关于Woocommerce 类别说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆