cookies - Automatically Log Out UserX when visiting WooCommerceStore

I developed a Web-Plattform, and Users Log into a DemoUser in order to Check-Out the Dashboard functionality.Now the pro

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 1
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745270144a4619694.html

相关推荐

  • cookies - Automatically Log Out UserX when visiting WooCommerceStore

    I developed a Web-Plattform, and Users Log into a DemoUser in order to Check-Out the Dashboard functionality.Now the pro

    20小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信