Automattic\WooCommerce\Internal\ProductFilters

TaxonomyHierarchyData::compute_ancestorsprivateWC 1.0

Compute ancestor chain for a term.

Method of the class: TaxonomyHierarchyData{}

No Hooks.

Returns

Array. Array of ancestor term IDs (bottom-up).

Usage

// private - for code of main (parent) class only
$result = $this->compute_ancestors( $term_id, $parent_lookup ): array;
$term_id(int) (required)
The term ID.
$parent_lookup(array) (required)
Parent relationships.

TaxonomyHierarchyData::compute_ancestors() code WC 10.3.3

private function compute_ancestors( int $term_id, array $parent_lookup ): array {
	$ancestors  = array();
	$current_id = $term_id;

	while ( isset( $parent_lookup[ $current_id ] ) && $parent_lookup[ $current_id ] > 0 ) {
		$parent_id   = $parent_lookup[ $current_id ];
		$ancestors[] = $parent_id;
		$current_id  = $parent_id;
	}

	return $ancestors;
}