Boris Zegarac
Boris Zegarac

Reputation: 531

Add tag info under single product page

I have 1 tag attached to every product under my store. What I want is to show that tag informations under single product page, tag infos like description and title. How do I do that, do I use query and then echo the results or something else.

Upvotes: 0

Views: 884

Answers (1)

Raunak Gupta
Raunak Gupta

Reputation: 10809

You may use woocommerce_product_meta_end hook to render custom HTML just before product meta, and use get_the_terms to get the tag's detail.

Here is a sample code:

add_action('woocommerce_product_meta_end', 'wh_renderProductTagDetails');

function wh_renderProductTagDetails()
{
    global $product;
    $tags = get_the_terms($product->get_id(), 'product_tag');
    //print_r($tags);
    if (empty($tags))
        return;
    foreach ($tags as $tag_detail)
    {
        echo '<p> Title: ' . $tag_detail->name . '</p>'; //to print title
        echo '<p> Desc: ' . $tag_detail->description . '</p>'; //to print description
    }
}

Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.

Hope this helps!

Upvotes: 1

Related Questions