In WooCommerce, when you visit shop page you can see all product display with product name but you didn’t see product with product category name because bydefault Woocommerce doesn’t provide this functionality. If you want to dispaly category name in woocommerce loop than here is solution.
Add below line of code at the end of your theme’s functions.php file of your active child theme (or theme) and Save the file. It display all category name in shop page.
add_action( 'woocommerce_before_shop_loop_item_title', 'add_categoryname_product_loop', 25);
function add_categoryname_product_loop()
{
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 ' ';
}
}
}
1 Comment. Leave new
Thank you, this works.