I have been able to show a list of Woocommerce category terms hierarchically. Now I'm struggling to get the first category term in the list as the default one. since I'm presenting the parent categories as tab links and the subcategories as tab contents. So how can get the first parent category that comes up as the default active tab?
I guess we could try to get something like:
<button class="tablinks <?php if ( $first_element == $default_active_tab ) echo esc_attr( 'active' ); ?>"
This is the code to get all parent product category terms,
<?php
$parent_args = array(
'taxonomy' => 'product_cat',
'hide_empty' => true,
'parent' => 0
);
$product_cat = get_terms( $parent_args );
foreach ($product_cat as $parent_cat)
{
echo'<buttonclass="tablinks"onclick="myFunction(event,\''.$parent_cat->name.'\')">'.$parent_cat->name.'</button>';
}
?>