Adding 400 product categories with their hierarchy to a navigation menu

Ok, I found a solution.

I used a combination of a plugin that allows me to add shortcode to menus and creating a new shortcode for product categories in functions.php.

Here is the code for the shortcode:

function display_product_categories_hierarchy($parent_id = 0, $first = true) {
    $args = array(
        'taxonomy'     => 'product_cat',
        'hide_empty'   => false,
        'parent'       => $parent_id
    );
    
    $categories = get_categories($args);
    if ($categories) {
        if ($first){
        echo '<ul class="boutiquemenu">';
        } else{
        echo '<ul>';
        }
        
        foreach ($categories as $category) {
            echo '<li><a href="' . get_term_link($category) . '">' . $category->name . '</a>';
            display_product_categories_hierarchy($category->term_id, false); // Recursive call
            echo '</li>';
        }
        echo '</ul>';
    }
}

function product_categories_hierarchy_shortcode() {
    ob_start(); // Start output buffering
    display_product_categories_hierarchy(); // Call the function
    return ob_get_clean(); // Return the output
}
add_shortcode('product_categories_hierarchy', 'product_categories_hierarchy_shortcode');

I added a if ($first) to be able to add a class to where this shortcode would be added.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino