正如我在标题中提到的,我想在主题的头文件中显示类别名称及其描述。
我尝试使用从搜索中获得的几个函数,就像我在下面尝试的那样,我已将其添加到我的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);
请指导我如何显示当前产品的类别名称及其描述?
最佳答案
试试这个,
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
希望有帮助..
关于wordpress - 如何在 WordPress 主题标题中显示 woocommerce 产品的类别名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21419138/