最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cookies - Automatically Log Out UserX when visiting WooCommerceStore

programmeradmin1浏览0评论

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();
    }
} 
发布评论

评论列表(0)

  1. 暂无评论