登录后的Woocommerce重定向到管理仪表板以实现客户角色

时间:2020-07-17 11:13:12

标签: php wordpress woocommerce

我正在使用此代码在woocommerce登录后将具有角色客户的用户重定向到。 (来自woocommerce after login redirect的代码)

function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'shop' ) );
if( $role == 'administrator' ) {
//Redirect administrators to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'shop-manager' ) {
//Redirect shop managers to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'editor' ) {
//Redirect editors to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'author' ) {
//Redirect authors to the dashboard
$redirect = $dashboard;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
//Redirect customers and subscribers to the "My Account" page
$redirect = $dashboard;
} else {
//Redirect any other role to the previous visited page or, if not available, to the home
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 ); 

对于客户角色,它不会重定向到仪表板页面,而是将其重定向到woo的默认“我的帐户”页面。如果我放置任何前端页面进行重定向,例如“商店”,“购物车”,则它会正确重定向,但不允许客户/订户访问wordpress管理区域。我试图创建一个具有与客户相同功能的新角色,但它也不允许访问仪表板(管理区域)。我只想在管理区域中创建一些页面,并仅授予那里的客户(或任何新角色)访问权限。

请帮助我。

0 个答案:

没有答案