Tagged: display, woocommerce
Hello,
I need some help with woocommerce. On my shop page (not single product page) I want to display the product category right between the product title and the product price. Is there an easy way without having to modify theme files (my site runs with an enfold child theme)? Any help would be greatly appreciated.
Thanks.
Hi StuWeTueHo!
You can use following code
add_action( 'woocommerce_after_shop_loop_item_title', 'avia_add_product_cat', 1);
function avia_add_product_cat()
{
global $product;
$product_cats = wp_get_post_terms($product->id, 'product_cat');
$count = count($product_cats);
foreach($product_cats as $key => $cat)
{
echo $cat->name;
if($key < ($count-1))
{
echo ', ';
}
else
{
echo '<br/>';
}
}
}
Insert it at the bottom of functions.php.
Cheers!
Peter
Works perfectly. Thanks Peter!
Your support earns more than 5 stars.
Hi!
Great, glad I could help you :)
Best regards,
Peter