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?
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.
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.
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?
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;
}
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();
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.
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.