0
Personal as I take the parent category of a registered product, as per ex:
Categoria Pai
-categoria filho 1
-produto cadastrado 1
-produto cadastrado 2
-categoria filho 2
-categoria filho 3
I am using a webhook in my functions.php, it shows the categories but not being the parent category the first to appear, because I think because it is in alphabetical order it does this. Follows 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 );
Is it possible to show only the parent category? Thanks in advance for the help!
Put the structure of your table of categories to help. But trying to anticipate, if your table of categories has auto-relationships, just in your "SELECT" categories you only search for those that have the foreign key (auto-relationship) blank (null)
– Gildonei