Reputation: 368
I have my shop set up as follows:
Shop page > Category > Subcategory > Product
The shop page shows a list of categories in a grid format, with a title and thumbnail for each category.
The Category page shows a list of categories in a grid format, with a title and thumbnail for each category.
I would like each of these grid items to also show the category description.
This is where I've got to so far (functions.php), which outputs the static text in the correct place. I can't figure out how to call the dynamic category description where the static text currently outputs.
function my_theme_woocommerce_taxonomy_archive_description() {
echo '<div class="term-description">' . 'Code to show description here please' . '</div>';
}
add_action( 'woocommerce_after_subcategory_title', 'my_theme_woocommerce_taxonomy_archive_description');
Upvotes: 1
Views: 2399
Reputation: 21
I was able to display the category description with this:
add_action( 'woocommerce_after_subcategory_title', 'custom_add_product_description', 12);
function custom_add_product_description ($category) {
$cat_id = $category->term_id;
$prod_term = get_term($cat_id,'product_cat');
$description = $prod_term->description;
echo '<div class="term-description">' .$description. '</div>';
}
Upvotes: 2
Reputation: 548
Can you please try this
function my_theme_woocommerce_taxonomy_archive_description($category) {
$category_id = $category->term_id;
echo '<div class="term-description">' . category_description( $category_id ). '</div>';
}
add_action( 'woocommerce_after_subcategory_title', 'my_theme_woocommerce_taxonomy_archive_description');
OR else try this one
add_action( 'woocommerce_after_subcategory_title','custom_add_product_description', 12);
function custom_add_product_description ($category) {
$cat_id = $category->term_id;
$prod_term = get_term($cat_id,'product_cat');
$description= $prod_term->description;
echo '<div class="term-description">'.$description.'</div>';
}
Try this one
function addcatagorydescription( $category ) {
echo '<div class="term-description">' . $category->description . '</div>';
}
add_action( 'woocommerce_after_subcategory_title', 'addcatagorydescription', 10, 1 );
Upvotes: 5