How to show product category names in product page??
-
How to show product category names in product page??
-
Can you share the screenshot where you want it because category names are already fetching?
-
@devansh-webkul i want to show it in product detail page how to fetch it.
{{$product->category->name}} not working -
-
@bzay23 said in How to show product category names in product page??:
{{$product->category->name}}
{{$product->categories->name}} also not working. Anyone got a solution?
-
You can't directly call
name
on thecategories
. Just die and dump$product->categories
, you will get to know. -
@bzay23 said in How to show product category names in product page??:
How to show product category names in product page
function my_add_woo_cat_class($classes) {
$wooCatIdForThisProduct = "?????"; //help! // add 'class-name' to the $classes array $classes[] = 'my-woo-cat-id-' . $wooCatIdForThisProduct; // return the $classes array return $classes;
}
//If we're showing a WC product page
if (is_product()) {
// Add specific CSS class by filter
add_filter('body_class','my_add_woo_cat_class');
}
source: stackoverflow