1
Everybody, good afternoon, everybody.
I need to get the last child of a category within a product loop:
Categoria
-categoria filho
--categoria ultimo filho
It always gives me the Father, ie 'Category':
<?php
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
$single_cat = array_shift( $product_cats );
if( ! empty( $product_cats ) ) {
$single_cat = array_shift( $product_cats );
$top_term = $single_cat;
if( $top_term->parent > 0 ) {
while( $top_term->parent > 0 ) {
$top_term = get_term( $top_term->parent, 'product_cat' );
}
} else {
$attr = 'sem parent';
}
$attr = $top_term->slug;
} else {
$attr = 'sem categoria';
}
?>
André Ribeiro, help awe, man.
– Lollipop