Addons
4 years ago
License
4 years ago
Pro
4 years ago
VariationOptions
4 years ago
CategoriesService.php
4 years ago
ScheduledExport.php
4 years ago
SnippetParser.php
4 years ago
WooCommerceVersion.php
4 years ago
CategoriesService.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Service; |
| 4 | |
| 5 | |
| 6 | class CategoriesService |
| 7 | { |
| 8 | public function getTaxonomyHierarchy($parent = 0) |
| 9 | { |
| 10 | $termsConfig = array( |
| 11 | 'taxonomy' => 'product_cat', |
| 12 | 'hide_empty' => false, |
| 13 | 'parent' => $parent |
| 14 | ); |
| 15 | |
| 16 | $terms = \get_categories($termsConfig); |
| 17 | |
| 18 | $children = array(); |
| 19 | |
| 20 | foreach ($terms as $term) { |
| 21 | |
| 22 | $item = array( |
| 23 | 'id' => $term->term_id, |
| 24 | 'title' => $term->name, |
| 25 | 'children' => $this->getTaxonomyHierarchy($term->term_id) |
| 26 | ); |
| 27 | $children[] = $item; |
| 28 | } |
| 29 | |
| 30 | return $children; |
| 31 | } |
| 32 | } |