WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::build_category_tree() protected WC 1.0

Build hierarchical tree of categories.

{} It's a method of the class: ProductCategories{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->build_category_tree( $categories );
$categories(array) (required)
List of terms.

Code of ProductCategories::build_category_tree() WC 5.6.0

protected function build_category_tree( $categories ) {
	$categories_by_parent = [];

	foreach ( $categories as $category ) {
		if ( ! isset( $categories_by_parent[ 'cat-' . $category->parent ] ) ) {
			$categories_by_parent[ 'cat-' . $category->parent ] = [];
		}
		$categories_by_parent[ 'cat-' . $category->parent ][] = $category;
	}

	$tree = $categories_by_parent['cat-0'];
	unset( $categories_by_parent['cat-0'] );

	foreach ( $tree as $category ) {
		if ( ! empty( $categories_by_parent[ 'cat-' . $category->term_id ] ) ) {
			$category->children = $this->fill_category_children( $categories_by_parent[ 'cat-' . $category->term_id ], $categories_by_parent );
		}
	}

	return $tree;
}