Title: Determine position
Last modified: August 31, 2016

---

# Determine position

 *  [alusion](https://wordpress.org/support/users/alusion/)
 * (@alusion)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/determine-position/)
 * Hello,
 * So I have the WPML Language Switcher added to the menu. WPML puts the switcher
   at the end of the menu.
 * WooCommerce Menu Cart also puts the menu item at the end of the menu which dominates
   the WPML Language Switcher and results in this:
    [http://prntscr.com/ajdlwz](http://prntscr.com/ajdlwz)
 * Is there a way to give the Menu Cart less priority? I would like to have the 
   language flags at the end instead of the Menu Cart.
 * Thank you.
 * [https://wordpress.org/plugins/woocommerce-menu-bar-cart/](https://wordpress.org/plugins/woocommerce-menu-bar-cart/)

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/determine-position/#post-7204735)
 * Hi! Unfortunately it is not possible to influence the priority of Menu Cart. 
   You may want to check the alignment setting though, if that’s set to ‘right’,
   this may be a simple matter of using the default alignment.
 * A more complicated solution is modifying the position of the menu cart item with
   jQuery:
 *     ```
       add_action( 'wp_footer', 'wpmenucart_move_position' );
       function wpmenucart_move_position() {
           ?>
           <script type="text/javascript">
           jQuery(document).ready(function($) {
               $(".wpmenucartli").each( function() {
                   // count number of items in menu
                   $parent_menu = $(this).closest('ul');
                   var items_count = $parent_menu.children('li').length;
                   var position = items_count - 1; // could be - 2 or 3, not sure about the WPML menu items
                   $(this).insertBefore( $parent_menu.children('li').eq(position) );
               });
           });
           </script>
           <?php
       }
       ```
   
 * If you don’t like using jQuery for this, there’s an even more complex server 
   side/PHP solution:
 *     ```
       /**
        * Apply WP Menu Cart repositioning filter to all menus from the settings
        */
       add_action( 'init', 'wpmenucart_filter_nav_menus' );
       function wpmenucart_filter_nav_menus() {
           global $wpMenuCart;
           // exit if no shop class is active
           if ( !isset($wpMenuCart->shop) )
               return;
           // exit if no menus set
           if ( !isset( $wpMenuCart->options['menu_slugs'] ) || empty( $wpMenuCart->options['menu_slugs'] ) )
               return;
           if ( $wpMenuCart->options['menu_slugs'][1] != '0' ) {
               add_filter( 'wp_nav_menu_' . $wpMenuCart->options['menu_slugs'][1] . '_items', 'wpmenucart_reposition_item' , 999, 2 );
           }
       }
   
       /**
        * Modify the $items string to put Menu Cart in a predefined position
        */
       function wpmenucart_reposition_item( $items, $args ) {
           $new_position = 2; // change this to the position of your choice
           // we need to add a parent node to be able to handle this properly
           $ul = '<ul id="wpmenucart-menu">'.$items.'</ul>';
   
           // $ul is flat HTML, so we convert it to DomDocument first
           $dom = new DOMDocument();
           $dom->loadHTML($ul, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
           $dom_ul = $dom->getElementById('wpmenucart-menu');
           $wpmc_item = $dom->getElementById('wpmenucartli');
   
           $node_position = 1;
           foreach ($dom_ul->childNodes as $childNode) {
               // skipping non-li nodes
               if ( !isset($childNode->tagName) || $childNode->tagName != 'li' ) {
                   $new_position++;
                   $node_position++;
                   continue;
               }
   
               // exit if we've found our node
               if ($new_position == $node_position) {
                   $before = $childNode;
                   break;
               }
   
               $node_position++;
           }
   
           // now that we know which node we want to put the Menu Cart before, we can move it
           $dom_ul->insertBefore(
               $wpmc_item,
               $before
           );
   
           // convert dom back to HTML
           $ul = $dom->saveHTML();
   
           // strip our ul wrapper again
           $open_ul_pos  = strpos($ul, '<ul id="wpmenucart-menu">') + strlen('<ul id="wpmenucart-menu">');
           $close_ul_pos = strrpos($ul, '</ul>');
           $snippet_length = $close_ul_pos - $open_ul_pos;
           $items = substr($ul, $open_ul_pos, $snippet_length);
   
           return $items;
       }
       ```
   
 * But like I said, this is pretty advanced stuff…
 * Hope that helps though!
    Ewout

Viewing 1 replies (of 1 total)

The topic ‘Determine position’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-menu-bar-cart/assets/icon-256x256.png?rev=2190481)
 * [Menu Cart for WooCommerce](https://wordpress.org/plugins/woocommerce-menu-bar-cart/)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-menu-bar-cart/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-menu-bar-cart/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-menu-bar-cart/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-menu-bar-cart/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Ewout](https://wordpress.org/support/users/pomegranate/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/determine-position/#post-7204735)
 * Status: not resolved