admin管理员组文章数量:1417554
I developed a Web-Plattform, and Users Log into a DemoUser in order to Check-Out the Dashboard functionality.
Now the problem is, that once they are happy with what they see and visit the woocommerce store - they are still logged in and would buy the service as DemoUser.
This seems to be a quiet unique issues, because even though I spent hours on research .. I am barely a step closer to a solution.
How can i log out the Demoaccount once the User visits the Woocommerce-Store?
I developed a Web-Plattform, and Users Log into a DemoUser in order to Check-Out the Dashboard functionality.
Now the problem is, that once they are happy with what they see and visit the woocommerce store - they are still logged in and would buy the service as DemoUser.
This seems to be a quiet unique issues, because even though I spent hours on research .. I am barely a step closer to a solution.
How can i log out the Demoaccount once the User visits the Woocommerce-Store?
Share Improve this question asked Aug 4, 2019 at 10:19 PhilippPhilipp 11 Answer
Reset to default 0You should use one of the actions that occur after parse_query
, because then the variables on which the conditional tags are based are set. Such action can be template_redirect
. The conditional tag will allow you to check if the current page is a store page. To log out the user, use the wp_logout()
function.
add_action('template_redirect', 'se344334_logout_demo_user', 9);
function se344334_logout_demo_user()
{
if ( ! is_user_logged_in() )
return;
$curr_user = wp_get_current_user();
if ( 'DemoUser' == $curr_user->user_login &&
(is_woocommerce() || is_checkout() || is_cart()) )
{
// destroy user "session"
wp_logout();
// redirect to current page after
wp_redirect( home_url( $_SERVER['REQUEST_URI'] ) );
die();
}
}
本文标签: cookiesAutomatically Log Out UserX when visiting WooCommerceStore
版权声明:本文标题:cookies - Automatically Log Out UserX when visiting WooCommerceStore 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745270143a2650839.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论