I have been trying to display the product sub-category name above the product title on the Shop or Product Archive page.
I’ve tried the code below but I am not sure how to get sub-categories instead of the category:
function category_single_product(){
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( $product_cats && ! is_wp_error ( $product_cats ) ){
$single_cat = array_shift( $product_cats ); ?>
<h2 itemprop="name" class="product_category_title"><span><?php echo $single_cat->name; ?></span></h2>
2
Answers
You can use
woocommerce_single_product_summary
and set priority. Try the below code. Code will go in your active theme functions.php file.Tested and Works
you can use get_term_children() function
I hope this will help you, Visit to get more info https://developer.wordpress.org/reference/functions/get_term_children/