Personal as I get the parent category of a product registered, such as eg:
Categoria Pai
-categoria filho 1
-produto cadastrado 1
-produto cadastrado 2
-categoria filho 2
-categoria filho 3
I'm using a webhook in my functions.php, it shows the categories but the parent category is not the first one to appear because I think it should be in alphabetical order so it does. Follow the code:
// adiciona no titulo a categoria do produto
function wpa89819_wc_single_product(){
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( $product_cats && ! is_wp_error ( $product_cats ) ){
while (!empty($product_cats)) {
$single_cat = array_shift( $product_cats ); ?>
<h2 itemprop="name" class="product_category_title"><span><?php echo $single_cat->name; ?></span></h2>
}
}
}
add_action( 'woocommerce_single_product_summary', 'wpa89819_wc_single_product', 2 );
Can you just show the parent category? Thanks in advance for the help!