Reputation: 531
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
Reputation: 10809
You may use
woocommerce_product_meta_end
hook to render custom HTML just before product meta, and useget_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