Automattic\WooCommerce\Blocks\BlockTypes

ProductCategories::fill_category_children()protectedWC 1.0

Build hierarchical tree of categories by appending children in the tree.

Method of the class: ProductCategories{}

No Hooks.

Return

Array.

Usage

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

ProductCategories::fill_category_children() code WC 9.4.2

protected function fill_category_children( $categories, $categories_by_parent ) {
	foreach ( $categories 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 $categories;
}