get_the_terms and get_term_by problems with showing categories and subcategories
-
Hello everyone,
The following code displays category linked to subcategories. The problem is that only one subcategory is shown despite several are available.
How can I modify this code so more subcategories($val) are shown on the page?
add_filter("woocommerce_product_tabs", "custom_tabs"); function custom_tabs( $_original ) { global $post; $aTerms = get_the_terms($post->ID, "product_cat"); $aUse = array(); foreach( $aTerms as $oTerm ) { if( $oTerm->parent > 0 ) { $oParent = $aTerms[$oTerm->parent]; if( empty($oParent) ) { $oParent = get_term_by("id", $oTerm->parent, "product_cat"); } // Original line $aUse[$oParent->name] = $oTerm->name; } } echo "<div class='specifications'>"; foreach( $aUse as $cat => $val ) { ?> <div class="spec-wrapper"> <div class="type"> <?php echo $cat; ?>: </div> <div class="value"> <?php echo $val; ?> </div> </div> <?php } echo "</div>"; return $_original; }
This is the page:
https://www.legrandcru.nl/product/soave-classico-azienda-agricola-fornaro-2013/Serveertip is a category and Vis gestoofd is a subcategory, but there are more subcategories but they don’t show up.
Alot of thanks in advance for your time, hope you can help me out.
Greetings,
Mickey
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get_the_terms and get_term_by problems with showing categories and subcategories’ is closed to new replies.