Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterTaxonomy::sort_hierarchy_termsprivateWC 1.0

Sort hierarchical terms recursively maintaining parent-child relationships.

Method of the class: ProductFilterTaxonomy{}

No Hooks.

Returns

Array. Sorted hierarchical terms.

Usage

// private - for code of main (parent) class only
$result = $this->sort_hierarchy_terms( $terms, $orderby, $order, $taxonomy_counts );
$terms(array) (required)
Hierarchical terms array with children.
$orderby(string) (required)
Sort field (name, count, menu_order).
$order(string) (required)
Sort direction (ASC, DESC).
$taxonomy_counts(array) (required)
Context-aware term counts.

ProductFilterTaxonomy::sort_hierarchy_terms() code WC 10.3.6

private function sort_hierarchy_terms( $terms, $orderby, $order, $taxonomy_counts ) {
	foreach ( $terms as $term ) {
		if ( ! empty( $term['children'] ) ) {
			$term['children'] = $this->sort_terms_by_criteria( $term['children'], $orderby, $order, $taxonomy_counts );
		}
	}
	$sorted = $this->sort_terms_by_criteria( $terms, $orderby, $order, $taxonomy_counts );
	return $sorted;
}