How do I display the categories of an individual product under the product name on the Shop page listing?
screenshot of Shop page:
How do I display the categories of an individual product under the product name on the Shop page listing?
screenshot of Shop page:
You should try this to show the product category above the price of each product.
add_filter( 'woocommerce_get_price_html', 'woo_shipping_with_price_display' );
add_filter( 'woocommerce_cart_item_price', 'woo_shipping_with_price_display' );
function woo_shipping_with_price_display( $price ) {
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
$text = '';
if ( $product_cats && ! is_wp_error ( $product_cats ) ){
$single_cat = array_shift( $product_cats );
$text = '<div itemprop="name" class="product_category_title"><span>'.__(esc_attr($single_cat->name)).'</span></div>';
}
if ($price == true) {
return $text . $price;
}
else {
return $text;
}
}
You can change/update html,class etc.. from line:
$text = '<div itemprop="name" class="product_category_title"><span>'.__(esc_attr($single_cat->name)).'</span></div>';