How to change the position of menu item?

Ubermenu is great, but probably unnecessary if this is all you’re trying to do. There are a ton of different ways to do this. Here’s a couple:


1) Custom Walker

<?php
// custom walker targeting products menu
class productMenu extends Walker_Nav_Menu {
    function end_el(&$output, $item, $depth=0, $args=array()) {

    if( 'Products' == $item->title ){
        // PRODUCT SUBMENU STUFF
        $output .= '<ul class="sub-menu">




        </ul>';
    }
    $output .= "</li>\n";  
    }
}


// new menu with walker
wp_nav_menu(
    array(
        'theme_location' => 'primary',
        'walker' => new productMenu
    )
);

2) Just add the ones you want after products to the filter as well

add_filter( 'wp_nav_menu_items', 'add_my_terms', 10, 2 );

function add_my_terms( $items ) {
    global $post;        
    $items .= '<li class="dropdown  "><a class="dropdown-toggle " data-toggle="dropdown" href="#">Products</a><ul class="dropdown-menu  coldrpprd ">';
    $terms = get_terms( 'product_cat', $args );
    $nmr=0;
    $args = array(
        'hierarchical' => 1,
        'show_option_none' => '',
        'hide_empty' => 0,
        'parent' => $term->term_id,
        'taxonomy' => 'product_cat'
    );
    $subcats = get_terms( 'product_cat', $args );        
    foreach ( $terms as $term ) {
        $category_name = $term->name;
        $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($category_thumbnail);
        $nmr++ ;         
        if ( $nmr <= 3 ) {
            $items .= '<li class="menuli">'.'<img class="category-image " src="'.$image.'">'.'<a  href="' . get_term_link($term) . '">' . $term->name . '</a></li>';
            $items .= '<ul>';
            foreach ( $subcats as $sc ) {
                $link = get_term_link( $sc->slug, $sc->taxonomy );
                $items .= '<li class="wooc_sclist"><a href="'. $link .'">'.$sc->name.'</a></li>';
            }
            $items .=  '</ul>';
        }
    }
    $items .= '</ul></li><li><a href="#">Products</a></li>';        
    return $items;
    return 
}

3) Just use your function without wp_nav_menu() and hardcode it all. Is it really necessary to have to have those menus editable in the backend? If not just do this:

<ul>
<li>Servizi</li>
<?php echo add_my_terms(); ?>
<li>Download</li>
<li>Contatti</li>
<li>Pricacy</li>
</ul>

4) If you really want to make this work without walker you could probably use wp_get_nav_menu_items() and search for product menu item by id and add submenu, but this is unnecessarily complicated for your task in my opinion.

5) Create two separate menus one before and one after your custom php.

  <?php wp_nav_menu(
        array(
            'theme_location' => 'primary_before',
        )
    ); ?>
   <ul>
   <?php echo add_my_terms(); ?>
   </ul>
   <?php wp_nav_menu(
        array(
            'theme_location' => 'primary_after'
        )
    ); ?>

6) Use shortcodes.

// Turn function into shortcode
function add_my_terms( $items ) {
    global $post;        
    $items .= '<ul class="dropdown-menu  coldrpprd ">';
    $terms = get_terms( 'product_cat', $args );
    $nmr=0;
    $args = array(
        'hierarchical' => 1,
        'show_option_none' => '',
        'hide_empty' => 0,
        'parent' => $term->term_id,
        'taxonomy' => 'product_cat'
    );
    $subcats = get_terms( 'product_cat', $args );        
    foreach ( $terms as $term ) {
        $category_name = $term->name;
        $category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($category_thumbnail);
        $nmr++ ;         
        if ( $nmr <= 3 ) {
            $items .= '<li class="menuli">'.'<img class="category-image " src="'.$image.'">'.'<a  href="' . get_term_link($term) . '">' . $term->name . '</a></li>';
            $items .= '<ul>';
            foreach ( $subcats as $sc ) {
                $link = get_term_link( $sc->slug, $sc->taxonomy );
                $items .= '<li class="wooc_sclist"><a href="'. $link .'">'.$sc->name.'</a></li>';
            }
            $items .=  '</ul>';
        }
    }
    $items .= '</ul>';        
    return $items;
}
add_shortcode('product_submenu', 'add_my_terms');



// Allow shortcodes to render in menu description fields
add_filter('wp_nav_menu_items', 'do_shortcode');
add_filter('wp_nav_menu', 'do_shortcode', 11);
if( !function_exists('shortcode_my_menu_descriptions') ) {
    function shortcode_my_menu_descriptions( $item_output, $item ) {
        if ( !empty($item->description)) {
             $output = do_shortcode($item->description);
             if ( $output != $item->description )
                  $item_output = $output;  
            }
        return $item_output;    
    }
    add_filter("walker_nav_menu_start_el", "shortcode_my_menu_descriptions" , 10 , 2);
}

Using this method you can create your menu as normal in the order you want and then just add [product_submenu] in the description field in the product menu item.

7) Using plugins

Beside ubermenu there is also https://wordpress.org/plugins/megamenu/ and https://wordpress.org/plugins/shortcode-in-menus/ which can help you achieve your results and are both free.