2013-10-08 143 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; ?>