How to change order of my-account-menu items

So I just added some headlines in the my account menu (and made them not clickable with css). It worked great. And when changing order of theese (and the user_edit_settings) I can control their position. But I cannot order any of the other enteties in the menu. Here is my code. Am I using the wrong names? (I took them from the html). If so, where do I find the correct names for the menu items?


add_filter( 'hivepress/v1/menus/user_account', function( $menu ) {
    if ( isset( $menu['items']['listings-edit'] ) ) {
        $menu['items']['listings-edit']['_order'] = 60;
    }
	if ( isset( $menu['items']['vendor-calendar'] ) ) {
        $menu['items']['vendor-calendar']['_order'] = 30;
    }
	if ( isset( $menu['items']['Vendor-dashboard'] ) ) {
        $menu['items']['vendor-dashboard']['_order'] = 20;
    }
	if ( isset( $menu['items']['bookings-view'] ) ) {
        $menu['items']['bookings-view']['_order'] = 101;
    }
	if ( isset( $menu['items']['orders-edit'] ) ) {
        $menu['items']['orders-edit']['_order'] = 40;
    }
	if ( isset( $menu['items']['orders-view'] ) ) {
        $menu['items']['orders-view']['_order'] = 50;
    }
	if ( isset( $menu['items']['user-logout'] ) ) {
        $menu['items']['user-logout']['_order'] = 202;
    }
	if ( isset( $menu['items']['user_edit_settings'] ) ) {
        $menu['items']['user_edit_settings']['_order'] = 201;
    }
    return $menu;
}, 1000 );

add_filter( 'hivepress/v1/menus/user_account', function( $menu ) {
    $menu['items']['menu_headline_mina_uthyrningar'] = [
		'label'  => 'Mina uthyrningar',
		'_order' => 1,
    ];
	
	$menu['items']['menu_headline_det_jag_hyr'] = [
        'label'  => 'Det jag hyr',
        '_order' => 100,
    ];

    $menu['items']['menu_headline_ovrigt'] = [
        'label'  => 'Ă–vrigt',
        '_order' => 200,
    ];

    return $menu;
} );

Hi,

The array case is incorrect here since there is no suchlisting-edit. We recommend using var_dump($menu) to see the available menu items by keys.

Add the following temporary code to your functions.php file to display the menu keys:

add_action('init', function() {
    if (is_user_logged_in()) {
        add_filter('hivepress/v1/menus/user_account', function($menu) {
            var_dump($menu);
            return $menu;
        });
    }
});

Visit the “My Account” page while logged in to see the menu structure and keys.

Note down the correct keys for the menu items.

Thanks both of you!
That did the trick, almost. Two of the menu items I cannot find in the list displayed with the var_dump, and some I connot change the palcing event though I configuredit to the right name).

Okey, so I looked into it a bit more.

In the list I get wehen using var_dump there is no key for vendor dashboard (yyy.se/account/vendor/dashboard/), nor for yyy.se/account/bookings/, even though I can see them in the menu. Isn’t that strange?

This is the code I get:

array(3) {
	["items"]=> array(9) {
		["user_edit_settings"]=> array(2) { 
			["route"]=> string(23) "user_edit_settings_page" 
			["_order"]=> int(50)
		} 
		["user_logout"]=> array(3) { 
			["label"]=> string(8) "Sign Out" 
			["url"]=> string(33) "yyy.se/account/logout/" 
			["_order"]=> int(1000)
		} 
		["listings_edit"]=> array(2) { 
			["route"]=> string(18) "listings_edit_page" 
			["_order"]=> int(10)
		} 
		["orders_view"]=> array(3) { 
			["label"]=> string(14) "Beställningar" 
			["url"]=> string(36) "yyy.se/mitt-konto/orders/" 
			["_order"]=> int(40)
		} 
		["vendor_calendar"]=> array(2) { 
			["route"]=> string(20) "vendor_calendar_page" 
			["_order"]=> int(25)
		} 
		["bookings_view"]=> array(2) { 
			["route"]=> string(18) "bookings_view_page" 
			["_order"]=> int(27)
		} 
		["menu_headline_mina_uthyrningar"]=> array(2) { 
			["label"]=> string(16) "Mina uthyrningar" 
			["_order"]=> int(1)
		} 
		["menu_headline_det_jag_hyr"]=> array(2) { 
			["label"]=> string(11) "Det jag hyr" 
			["_order"]=> int(100)
		} 
		["menu_headline_ovrigt"]=> array(2) { 
			["label"]=> string(7) "Ă–vrigt" 
			["_order"]=> int(200)
		} 
	} 
	["context"]=> array(1) { 
		["page_title"]=> NULL 
	} 
	["attributes"]=> array(1) { 
		["class"]=> array(3) { 
			[0]=> string(9) "hp-widget" 
			[1]=> string(6) "widget" 
			[2]=> string(15) "widget_nav_menu" 
		} 
	}
}

Also, If you look at my first code above, I have been trying to change the _order, but for some reason it wont change at all.

The first number here is the integer I try to set to the order to, the number within parentasies is the number I get frĂĄn var_dump. In other words, still wrong order.

1 (1) -->				["menu_headline_mina_uthyrningar"]
110 (10) Annonser			["listings_edit"]
30 (25) Kalender			["vendor_calendar"]
101 (27) Inkomna bokningar   ["bookings_view"]
50 (40) Placed orders		["orders_view"]
201 (50) Inställningar		["user_edit_settings"]
100 (100) --> 			["menu_headline_det_jag_hyr"]
200 (200) --> 			["menu_headline_ovrigt"]
202 (1000) Sign Out			["user_logout"]

Is my code wrong somehow, or can’t I change the order?

(And if that is soleved, how can I change to order on the two that is not even showing in the var_dump list, how will I know the names?)

EDIT, UPDATE:
So I kind of solved my problem now without knowing how. Still did’t really fixed the above issues, but I got the right order somehow.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.