Reputation: 39
as i mentioned in the title, i want to show the category name & its description in the header file of my theme.
i tried to do with several functions which i got from search like i tried below, i have added this in my functions.php, but that not works
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>';
}
}
lastly i tried by including class WC_Product, but that not works too, i have below mentioned the code which i used for it
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);
Please guide how can i display the category name of the current product and & its description??
Upvotes: 2
Views: 11973
Reputation: 8272
Try this,
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>';
}
}
for more
Hope its helps..
Upvotes: 2