0
votes

I have a question regarding woocommerce and the product-pages. I want to output the text and pictures stored in the product category.

For example, if the product is connected to the categories "electro" and "car", I want to output the text and pictures stored in the woocommerce-category description of "electro" and "cars".

I used the following code, to get at least some information displayed, thats stored in the functions.php (like some text in the listitem)

add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );

function my_extra_button_on_product_page($category) {
    global $post;
    echo '<ul class="myCat"> ';

if ( has_term( 'Cocktails', 'product_cat' ) ) {
echo'
Wird gerne genutz in Rezepten f&uuml;r:<br />
<li class="icon-glass2">1</li>
';}
elseif ( has_term( 'Dressings', 'product_cat' ) ) {
echo'
<li>2</li>
';}
if ( has_term( 'Limonaden', 'product_cat' ) ) {
echo'
<li class="icon-glass2">3</li>
';}
elseif ( has_term( 'Kochen', 'product_cat' ) ) {
echo'
<li class="icon-glass2">4</li>
';} 
elseif ( has_term( 'Backen', 'product_cat' ) ) {
echo'
<i class="icon-glass2">5</i>
';} 
elseif (has_term ('shrub', 'product_cat')){echo 'shrub';}
 else {
echo 'test';
}echo '</ul><br style="clear:both;" /> ';}

There is however some code I found, but I dont know how to get it working with my code.

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>'.$description.'</div>';
}

I would be happy, if someone could help me putting those together.

1

1 Answers

0
votes
<?php 

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>';
        echo $term->description;
        echo '</div>';
    }
}

?>   

To add category description to single product page, using content-single-product.php template file,