我已经为这个问题开发了一个插件。下面还提供了无插件重定向的原始代码。
/**
* Redirect users to custom URL based on their role after login
**/
function wp_woo_custom_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( \'my-account\' ) );
if( $role == \'administrator\' ) {
//Redirect administrators to the dashboard
$admin_redirect = get_option(\'admin_redirect\');
$redirect = $admin_redirect;
} elseif ( $role == \'shop-manager\' ) {
//Redirect shop managers to the dashboard
$shop_manager_redirect = get_option(\'shop_manager_redirect\');
$redirect = $shop_manager_redirect;
} elseif ( $role == \'customer\' || $role == \'subscriber\' ) {
//Redirect customers and subscribers to the "My Account" page
$customer_redirect = get_option(\'customer_redirect\');
$redirect = $customer_redirect;
} 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\', \'wp_woo_custom_redirect\', 10, 2 );
使用插件或不使用代码,您是否感到舒适?您可以下载并安装我的插件“
WP WooCommerce Redirect“”