Automattic\WooCommerce\Blocks\BlockTypes
ProductFilterTaxonomy::get_hierarchical_terms
Get taxonomy terms ordered hierarchically.
Method of the class: ProductFilterTaxonomy{}
No Hooks.
Returns
Array|\WP_Error. Hierarchically ordered terms or error.
Usage
// private - for code of main (parent) class only $result = $this->get_hierarchical_terms( $taxonomy, $taxonomy_counts, $hide_empty, $orderby, $order );
- $taxonomy(string) (required)
- Taxonomy slug.
- $taxonomy_counts(array) (required)
- Term counts with term_id as key.
- $hide_empty(true|false) (required)
- Whether to hide empty terms.
- $orderby(string) (required)
- Sort field for siblings (name, count, menu_order).
- $order(string) (required)
- Sort direction (ASC, DESC).
ProductFilterTaxonomy::get_hierarchical_terms() ProductFilterTaxonomy::get hierarchical terms code WC 10.3.6
private function get_hierarchical_terms( string $taxonomy, array $taxonomy_counts, bool $hide_empty, string $orderby, string $order ) {
// Use TaxonomyHierarchyData for hierarchy operations.
$container = wc_get_container();
$hierarchy_data = $container->get( TaxonomyHierarchyData::class )->get_hierarchy_map( $taxonomy );
$sorted_term = $this->sort_hierarchy_terms( $hierarchy_data['tree'], $orderby, $order, $taxonomy_counts );
$flat_list = array();
$this->flatten_terms_list( $sorted_term, $flat_list );
if ( ! $hide_empty ) {
return $flat_list;
}
return array_filter(
$flat_list,
function ( $term ) use ( $taxonomy_counts ) {
return ! empty( $taxonomy_counts[ $term['term_id'] ] );
}
);
}