2014-01-28 42 views
2

正如我在标题中提到的,我想在我的主题的头文件中显示类别名称&其描述。如何在wordpress主题标题中显示woocomerce产品的类别名称

我试着与几个功能,我从搜索得到了像我在下面试图做的,我在加的functions.php这一点,但不是工作

function sk_show_product_category_description() { 
if (is_singular('product')) { 
    global $post, $product; 
    $categ = $product->get_categories(); 
    $term = get_term_by ('name' , strip_tags($categ), 'product_cat'); 

     echo '<div class="widget-background-wrapper"><div class="widget product-cat-description"><h4 class="widget-title">Note</h4>' . $term->description . '</div></div>'; 

} 
} 

最后,我试图通过包括类WC_Product,但这不也工作,我已经下文提到的,我用它

global $woocommerce, $post, $WC_Product; 
$file =$woocommerce->plugin_path.'/classes/abstracts/abstract-wc-product.php'; 
$getWooClass = include_once($file); 
    $test = $getWooClass->get_categories(122); 
var_dump($test); 

请指导我如何可以显示当前的产品和&其描述的类别名称的代码?

回答

2

试试这个,

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

     } 

    } 

more

希望它有助于..

+0

感谢@Jobin何塞 – TechChef

+0

欢迎您.. –

相关问题