• Resolved Jason Wong

    (@eljkmw)


    In the “my-account” page, I like to have Dashboard, Account Details, and Logout submenu links for Admin and Shop Manager user roles. How do I do this?

    Also, to have Dashboard redirect to wp-admin only for Admin and Shop Manager user roles.

    Please advice. Thank you very much.

    https://wordpress.org/plugins/woocommerce/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Those two items are kinda conflicting.

    See this wiki for removing tabs conditionally: https://github.com/woothemes/woocommerce/wiki/2.6-Tabbed-My-Account-page#adding-a-new-item-on-the-menu

    If you redirect to wp-admin from the dashboard for those roles though, why remove tabs if you just want to redirect?

    Thread Starter Jason Wong

    (@eljkmw)

    Thanks for the Wiki link, Caleb. I’ve added a function that redirects Admin and Shop Managers to wp-admin after they login from the frontend. However, they too get to access my-account on the frontend, which they’ve access to the tabs. Hence, my purpose of wanting to remove (or limit) the tabs for both user roles.

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Ahh, gotcha. That makes more sense.

    So yep, just unset whichever tabs you would like to with the woocommerce_account_menu_items filter. You can add in a conditional to check what the current user’s role is.

    Thread Starter Jason Wong

    (@eljkmw)

    Thanks, Caleb. The following lines of code is what I managed to produce.

    // Administrator and Shop Manager roles
    	if ( current_user_can( 'manage_woocommerce' ) ) {
    		$items = array(
    			'dashboard'		=> __( 'Dashboard', 'woocommerce' ),
    		//	'orders'		=> __( 'Orders', 'woocommerce' ),
    		//	'downloads'		=> __( 'Downloads', 'woocommerce' ),
    		//	'edit-address'		=> __( 'Addresses', 'woocommerce' ),
    		//	'payment-methods'	=> __( 'Payment Methods', 'woocommerce' ),
    			'edit-account'		=> __( 'Edit Account', 'woocommerce' ),
    			'customer-logout'	=> __( 'Logout', 'woocommerce' )
    		);
    	}
    
    	return $items;
    }
    add_filter( 'woocommerce_account_menu_items', 'wc_limit_account_menu_items' );

    This works fine to fulfill 90% of my needs. However, when I changed 'dashboard' => __( 'Dashboard', 'woocommerce' ), to 'wp-admin' => __( 'Dashboard', 'woocommerce' ),; it shows /my-account/wp-admin/ and not /wp-admin/ that I hoped for.

    What am I missing here?

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    It’s adding it as an endpoint for the my-account page. Maybe just set up a redirect? Otherwise, you can use this filter to change the url: https://github.com/woothemes/woocommerce/blob/7d9d091767586447f90b9dde7a1d93b256d70455/includes/wc-page-functions.php#L108

    add_filter( 'woocommerce_get_endpoint_url', 'wc_ninja_change_endpoint_url', 15, 4 );
    function wc_ninja_change_endpoint_url( $url, $endpoint, $value, $permalink ) {
    	if ( 'wp-admin' === $endpoint ) {
    		$url = 'http://shipping.dev/wp-admin';
    	}
    
    	return $url;
    }
    Thread Starter Jason Wong

    (@eljkmw)

    Many thanks, Caleb. Your suggested code worked perfectly.
    I made a small improvement to it, by replacing
    $url = 'http://shipping.dev/wp-admin';
    with
    $url = admin_url();

    Thread Starter Jason Wong

    (@eljkmw)

    Since I upgraded to WooCommerce v.2.6.14, I noticed the last above snippet no longer works.

    It reverts to showing /my-account/wp-admin/, and not /wp-admin/ that I wanted.

    Any ideas to resolve this, please? Thank you.

    Thread Starter Jason Wong

    (@eljkmw)

    I just liaised with the theme’s developer, and found out that its my-account template had forced the insertion of ‘/my-account/’.

    If this wasn’t the root cause, then the above snippet would’ve still worked fine.

    I think a simpler fix rather than adding the ‘woocommerce_get_endpoint_url’ filter. Just define the dashboard item like this:

    '../wp-admin' => __( 'Dashboard', 'woocommerce' )

    This works. I tested it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to remove submenu on "my-account" page for Admin & Shop Manager?’ is closed to new replies.