简体   繁体   中英

Woocommerce - Add description to category thumbs

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM