Наконец-то я разобрался, используя рекурсивную функцию:
private function _categoriaOrder($level = 0) {
echo "<ul>";
for($i = 0; $i < count($this->_mycats[$level]); $i++) {
echo "<li style='list-style-type: none;'><label style=\"margin-bottom:0;\" for=\"woo_id_categoria_{$this->_mycats[$level][$i]['id']}\"><input value=\"{$this->_mycats[$level][$i]['id']}\" id=\"woo_id_categoria_{$this->_mycats[$level][$i]['id']}\" name=\"woo_id_categoria[]\" type=\"checkbox\"> <span>" . $this->_mycats[$level][$i]['id'] . " " . $this->_mycats[$level][$i]['name'] . "</span></label>";
if(array_key_exists($this->_mycats[$level][$i]['id'], $this->_mycats)) {
$this->_categoriaOrder($this->_mycats[$level][$i]['id']);
}
echo "</li>";
}
echo "</ul>";
}
public function getCategoriaTree(){
$categorie = $this->woo->getCategoria(); //here is the object with categories from woocommerce
foreach($categorie as $k => $category){
$this->_mycats[(int)$category->parent][] = array(
'id' => $category->id,
'name' => $category->name,
);
$categories_ordered[(int)$category->parent] = $category;
}
ob_start();
$this->_categoriaOrder();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
используйте функцию getCategoriaTree()
для получения html.
Надеюсь, это кому-нибудь поможет, я потратил несколько часов на его получение.