Skip to content
Advertisement

woocommerce build categories tree

I have this categories into my wordpress (woocommerce), and I need to build a menù like this using data retrieved from woocommerce api.

enter image description here

What’s an efficient way to build a menù like this? I have tried to inspect wordpress code without figured out.

This API lets me retrieve all product categories.

https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-product-categories

this is the object obtained from request:

JavaScript

Advertisement

Answer

Finally I figured out, using a recursive function:

JavaScript

use the function getCategoriaTree() for retrieve html.enter image description here

I hope this could help someone, I spent some hours for get it.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement