当用户登录Woocommerce时,请打开MyAccount页面
我需要详细介绍我们提供的一系列服务。 在那个页面上,我想设置一个Tick Box,如果他们同意我们的销售人员打电话。
如果用户选择了这个 - 我想设置一个Session变量,我可以在Cart上使用。
答案 0 :(得分:0)
以下是一些可以指导您完成此操作的片段
登录后: -
// Custom redirect for users after logging in
add_filter('woocommerce_login_redirect', 'wcs_login_redirect');
function wcs_login_redirect( $redirect ) {
$redirect = 'http://google.com/';
return $redirect;
}
登录后但刚刚注册后: -
// Custom redirect for users after logging in
add_filter('woocommerce_registration_redirect', 'wcs_register_redirect');
function wcs_register_redirect( $redirect ) {
$redirect = 'http://google.com/';
return $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( 'myaccount' ) );
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 = $myaccount;
} 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 );