According to your description I’m assuming your each product has a category named Designers
and designer-name
subcategory under Designers
category.
In that case the following CODE will work for you (read the comments within the CODE for explanation):
function wc_shop_product_sub_category() {
// get the category object for "designers" category
$designers_category = get_term_by( 'name', 'designers', 'product_cat' );
if( $designers_category ) {
// this CODE returns all the sub-categories of "designers" category
// that belongs to the current product in the loop
$designers = wp_get_post_terms( get_the_ID(), 'product_cat', array( 'child_of' => $designers_category->term_id ) );
if ( $designers && ! is_wp_error( $designers ) ) {
// remember, there may be multiple sub categories for "Designers" category. So if you want to
// show multiple designers, you'll need to loop through the $designers array to show them all
$designer = array_shift( $designers );
?>
<h2 itemprop="name" class="product_category_title"><span><?php echo $designer->name; ?></span></h2>
<?php
}
}
}
// this will place the designers between title & price
add_action( 'woocommerce_shop_loop_item_title', 'wc_shop_product_sub_category' );
// this will place the designers after price
// add_action( 'woocommerce_after_shop_loop_item_title', 'wc_shop_product_sub_category' );