Join our new community forum for support & discussion

Join Now

Home Support General HivePress Re-Arrange My Account Menu Items

Re-Arrange My Account Menu Items

  • Author
    Posts
  • gsmobina

    I want to re-order the menu items on my account to the following:
    How can i do this?

    1. Listings
    2. Messages
    3. Favorites
    4. Membership
    5. Packages
    6. Orders
    7. Settings
    8. Sign out

    ihor developer

    You can do this via HivePress API using “hivepress/v1/menus/user_account” filter, menu items can be re-ordered in the same way as fields (via setting the “_order”).

    gsmobina

    like this?

    add_filter(
    	'hivepress/v1/menus/user_account',
    	function( $template ) {
    		return hivepress()->helper->merge_trees(
    			$template,
    			[
    				'blocks' => [
    				
    
    					'listings'          => [
    						'_order' => 0,
    					],
    						'messages' => [
    						'_order' => 1
    					],
    						'favorites' => [
    						'_order' => 3
    					],
    						'memberships' => [
    						'_order' => 4
    					],
    						'listung_packages' => [
    						'_order' => 5
    					],
    						'orders' => [
    						'_order' => 6
    					],
    						'settings' => [
    						'_order' => 7
    					],
    						'signout' => [
    						'_order' => 8
    					],
    				],
    			]
    		);
    	}
    );

    ——
    doesn’t seem to be working

    ihor developer

    Here’s an example:

    add_filter(
    	'hivepress/v1/menus/user_account/items',
    	function( $menu ) {
    		if ( isset( $menu['listings_edit'] ) ) {
    			$menu['listings_edit']['_order'] = 123;
    		}
    
    		return $menu;
    	}
    );
    gsmobina

    ok thank you. i’ll try this

    by the way is it possible to have a filter at the menu area? my client needs to show a country drop down, which by selecting will show only the selected country’s ads. I have set language and currency switcher dropdown for the site, so clients wants this dropdown next to this. if i am to do this, what best way would be this?

    gsmobina

    here is what i did. where am i gone wrong in this?

    add_filter(
    ‘hivepress/v1/menus/user_account/items’,
    function( $menu ) {
    if ( isset( $menu[‘listings_edit’] ) ) {
    $menu[‘listings_edit’][‘_order’] = 10;
    }
    if ( isset( $menu[‘messages’] ) ) {
    $menu[‘messages’][‘_order’] = 20;
    }
    if ( isset( $menu[‘favorites’] ) ) {
    $menu[‘favorites’][‘_order’] = 45;
    }
    if ( isset( $menu[‘memberships’] ) ) {
    $menu[‘memberships’][‘_order’] = 40;
    }
    if ( isset( $menu[‘user_listing_packages_view’] ) ) {
    $menu[‘user_listing_packages_view’][‘_order’] = 35;
    }
    if ( isset( $menu[‘woocommerce-orders’] ) ) {
    $menu[‘woocommerce-orders’][‘_order’] = 60;
    }
    if ( isset( $menu[‘user_edit_settings’] ) ) {
    $menu[‘user_edit_settingst’][‘_order’] = 70;
    }
    if ( isset( $menu[‘user_logout’] ) ) {
    $menu[‘user_logout’][‘_order’] = 80;
    }

    return $menu;
    }
    );

    ihor developer

    Try using this one instead:

    add_filter(
    	'hivepress/v1/menus/user_account/items',
    	function( $menu ) {
    		if ( isset( $menu['listings_edit'] ) ) {
    			$menu['listings_edit']['_order'] = 123;
    		}
    
    		return $menu;
    	},
    	10000
    );

    You can check page IDs with var_dump:

    var_dump($menu);

    For example, the favorites page has “listings_favorite” ID instead of “favorites”.

    gsmobina

    hi,

    I have been trying to do this for sometime.

    i tries var dump method after searching the net but i still don’t know how to do this properly.

    this is what i finaly wrote as a code snippet

    add_filter(
    ‘hivepress/v1/menus/user_account/items’,
    function( $menu ) {
    	if ( isset( $menu['listings_edit'] ) ) {
    			$menu['listings_edit']['_order'] = 1;
    		} 
    					if ( isset( $menu['messages_thread'] ) ) {
    			$menu['messages_thread']['_order'] = 12;
    		}
    			if ( isset( $menu['listings_favorite_page'] ) ) {
    			$menu['listings_favorite_page']['_order'] = 123;
    		}
    				if ( isset( $menu['memberships_view_page'] ) ) {
    			$menu['memberships_view_page']['_order'] = 1234;
    		}
    				if ( isset( $menu['user_listing_packages_view'] ) ) {
    			$menu['user_listing_packages_view']['_order'] = 12345;
    		}
    			if ( isset( $menu['orders_view'] ) ) {
    			$menu['orders_view']['_order'] = 123456;
    		}
    				if ( isset( $menu['user_edit_settings_pages'] ) ) {
    			$menu['user_edit_settings_page']['_order'] = 1234567;
    		}
    			if ( isset( $menu['user_logout'] ) ) {
    			$menu['user_logout']['_order'] = 12345678;}
    
    			//	echo var_dump($menu);
    			
    return $menu;
        
    });

    Please help me to sort this.

    ihor developer

    Please also add the “1000” priority after the function (like in the last snippet I suggested). Then you can uncomment echo var_dump($menu); for a moment and check the account page – it will output all the available menu items that you can re-order. The code you posted is correct, but some menu keys are not and also there should be 1000 priority (so your code is called only when all extensions add their menu items).

    gsmobina

    I did ihor, but no luck. what else could be the issue? can you tell me which menu keys are wrong and what i should add to fix it?

    ihor developer

    This code snippet should move the “Listings” menu item to the end:

    add_filter(
    	'hivepress/v1/menus/user_account/items',
    	function( $menu ) {
    		if ( isset( $menu['listings_edit'] ) ) {
    			$menu['listings_edit']['_order'] = 9999;
    		}
    
    		return $menu;
    	},
    	10000
    );

    You can start with it and copy the “if…” part with different menu item keys. If can’t check the $menu contents, please try removing the “_page” part from menu keys and it should be ok.

    gsmobina

    I commented the rest and added the order 9999 to listings. still it doesn’t move

    ihor developer

    Please try starting with the suggested code snippet above (instead of fixing the one you have), because it 100% works https://prnt.sc/vao9j6 Then you can copypaste this part:

    if ( isset( $menu['listings_edit'] ) ) {
    	$menu['listings_edit']['_order'] = 9999;
    }

    Changing the menu item ID, and re-order any menu items this way.

Viewing 13 posts - 1 through 13 (of 13 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.