Про погружение есть такая штука называется рекурсия
Вот пример реализации такого как вам надо, под себя подпилите
function wpp_bt_shop_by_menu_items() {
if ( false === ( $html = get_transient( 'wpp_bt_shop_by_nav' ) ) ) {
$html = '';
$locations = get_nav_menu_locations();
if ( $locations && isset( $locations['shop_by'] ) ) :
$menu = wp_get_nav_menu_object( $locations['shop_by'] );
$menu_items = wp_get_nav_menu_items( $menu );
foreach ( $menu_items as $menu_item ):
$term = $menu_item->type === 'taxonomy' ? get_term( $menu_item->object_id ) : null;
$html .= wpp_bt_crate_items_list( $term, $menu_item );
endforeach;
endif;
set_transient( 'wpp_bt_shop_by_nav', $html, 24 * HOUR_IN_SECONDS );
}
return apply_filters( 'wpp_bt_shop_by_nav_items', $html );
}
/**
* Product cat naw menu item
*
* @param $term
* @param $menu_item
*
* @return string
*/
function wpp_bt_crate_items_list( $term, $menu_item) {
$html = '';
if ( $menu_item === null || ( $menu_item !== null && $menu_item->menu_item_parent == 0 ) ) {
if ( $menu_item === null || ( $menu_item !== null && $menu_item->object === 'product_cat' ) ) {
if ( wpp_instock_product_count_in_term( $term->term_id ) > 0 || ( $menu_item->object_id === BT_LATEST_PRODUCT_TERM ) ) {
$children = get_categories(
array(
'hide_empty' => true,
'taxonomy' => 'product_cat',
'parent' => $term->term_id
)
);
$class = count( $children ) > 0 ? 'has-child' : 'cat-no-child';
$title = $menu_item ? $menu_item->title : $term->name;
$html .= sprintf( '<li class="cat-item cat-item-%s %s">', $term->term_id, $class );
$html .= sprintf( '<a href="%1$s" title="%2$s">%2$s</a>', get_term_link( $term->term_id ), $title );
if ( count( $children ) > 0 ) {
$html .= '<ul class="children">';
foreach ( $children as $child ) {
if ( $child->count > 0 ) {
$html .= wpp_bt_crate_items_list( $child, null );
}
}
$html .= '</ul>';
}
$html .= '</li>';
}
} else if ( $menu_item->object == 'custom' ) {
$children = get_menu_item_children(
array(
'parent' => $menu_item->ID
)
);
$class = count( $children ) > 0 ? 'has-child' : 'cat-no-child';
$html .= sprintf( '<li class="cat-item cat-item-%s %s">', $menu_item->ID, $class );
$html .= sprintf( '<a href="%1$s%2$s" title="%3$s">%3$s</a>', get_home_url(), $menu_item->url, $menu_item->title );
if ( count( $children ) > 0 ) {
$html .= '<ul class="children">';
foreach ( $children as $child ) {
$html .= sprintf( '<li class="cat-item cat-item-%s cat-no-child">', $child->ID );
$html .= sprintf( '<a href="%1$s%2$s" title="%3$s">%3$s</a>', get_home_url(), $child->url, $child->title );
}
$html .= '</ul>';
}
$html .= '</li>';
}
}
return $html;
}