Automattic\WooCommerce\Internal\ProductFilters

TaxonomyHierarchyData::build_term_treeprivateWC 1.0

Recursively build hierarchical term tree with depth and parent.

Method of the class: TaxonomyHierarchyData{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->build_term_tree( $tree, $term_id, $children, $temp_terms, $depth );
$tree(array) (required) (passed by reference — &)
Reference to tree array being built.
$term_id(int) (required)
Current term ID.
$children(array) (required)
Children relationships map (parent_id => [child_ids]).
$temp_terms(array) (required)
Term data indexed by term_id.
$depth(int)
Current depth level in hierarchy.

TaxonomyHierarchyData::build_term_tree() code WC 10.3.3

private function build_term_tree( &$tree, $term_id, $children, $temp_terms, $depth = 0 ) {
	$tree[ $term_id ]          = $temp_terms[ $term_id ];
	$tree[ $term_id ]['depth'] = $depth;

	if ( ! empty( $children[ $term_id ] ) ) {
		foreach ( $children[ $term_id ] as $child_id ) {
			$this->build_term_tree( $tree[ $term_id ]['children'], $child_id, $children, $temp_terms, $depth + 1 );
		}
	}
}