Вы можете использовать get_ancestors()
, а затем count()
на возвращенных товарах.Отсюда будет простая логика.
Как функция это будет выглядеть следующим образом:
function so50409656_count_ancestors( $object_id, $object_type ='', $resource_type='' ) {
$terms = get_ancestors( $object_id, $object_type, $resource_type );
return count($terms) + 1;
}
И затем вызывается так:
$term_depth = so50409656_count_ancestors( $term->term_id, 'your_term_type', 'taxonomy' );
if ( $term_depth === 1 ) :
// ..your top level ancestor action
elseif ( $term_depth === 2 ) :
// ..your direct child choice of actions here
elseif ( $term_depth === 3 ) :
// ..your second level child action here
endif;
РЕДАКТИРОВАТЬ:
Уточнил, что результатиз 1 будет предком верхнего уровня в соответствии с запросом OP для чего-то типа large
(в apple>large
), равного 2