WooCommerce – how to display product category above product? [closed]

The product title is added to the woocommerce_single_product_summary hook at priority 5, so you’ll want to add to the same hook with a lower (earlier) priority. You’d add this to your theme’s functions.php file. I presume when you say “category” you mean the WooCommerce product category, so this should return the first one and print it before the product title:

function wpa89819_wc_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>

<?php }
}
add_action( 'woocommerce_single_product_summary', 'wpa89819_wc_single_product', 2 );

Leave a Comment