2013-10-08 144 views
0

我有下一个代码: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>'; 

     } 

    } 

?> 

该代码将显示类别描述。问题 - 在子类别中,它将显示子类别描述+父级描述。

我如何显示描述分开:在父 - 父母的描述,和子 - 只有子描述?

回答

0

答案:

<?php 
global $post; 
$terms = get_the_terms('product_cat',$post->ID); 


      echo '<div style="direction:rtl;">'; 
      echo category_description(get_category_by_slug($terms)->term_id); 
      echo '</div>'; 

?> 
0

您可以使用此代码以显示产品类别描述 -

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