Documentation

Hide An Account Menu Item

Sometimes you may want to hide an item from the account menu. In version 1.0.3 I added a filter to make this possible.

Hide a menu item for all users

Add the following code to your theme’s functions.php file.

/**
 * Hide an account menu item.
 * 
 * @param array $hidden
 *
 * @return array
 */
function iconic_hidden_pages( $hidden ) {
	$hidden[] = 'example-page';

	return $hidden;
}

add_filter( 'iconic_wap_hidden_pages', 'iconic_hidden_pages', 10, 1 );

The filter accepts 1 parameter:

  • $hidden This is an array of page slugs. In this example we’re adding example-page as a hidden item.
adding a hidden menu item

This page will now be hidden from the menu. You can add more pages by duplicating this line $hidden[] = 'example-page';.

Hide a menu item for a specific user role

If you want to hide a menu item from a specific user role, you can do the following:

/**
 * Hide an account menu item.
 *
 * @param array $hidden
 *
 * @return array
 */
function iconic_hidden_pages( $hidden ) {
	if ( iconic_get_current_user_role() === 'wholesale' ) {
		$hidden[] = 'example-page';
	}

	return $hidden;
}

add_filter( 'iconic_wap_hidden_pages', 'iconic_hidden_pages', 10, 1 );

/**
 * Get current user role.
 * 
 * @return bool|string
 */
function iconic_get_current_user_role() {
	if( is_user_logged_in() ) {
		$user = wp_get_current_user();
		$role = ( array ) $user->roles;
		return $role[0];
	} else {
		return false;
	}
}

The code is much the same as before, except this time we’re using iconic_get_current_user_role() to determine if the user has the wholesale role. If they do, we’ll hide the example-page menu item.

Are you using WooCommerce Account Pages yet?

Start your 14-day free trial right now and get instant access to the features described in this article.

or learn more

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.

WooCommerce Account Pages by Iconic

WooCommerce Account Pages

Not got the plugin yet? Get instant access right now, free for 14 days.

or learn more

Still need help?

If you haven't found what you're looking for in our documentation, please contact support.

Get Support