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();
}
}
Related Posts:
- Deleting cookie to logout
- Disconnect automattically after X minutes
- Set Short Automatic Logout Time for One User
- PHP – setcookie(); not working
- How to share cookies and sessions between domain and subdomain?
- Is it possible to transfer a WordPress session to a different browser via query string?
- How does REST API cookie authentication work in WP 4.7?
- Why does it say: ‘Cookies are blocked or not supported’?
- Place a cookie when a specific page has been viewed?
- How to detect a user that is not logged in
- How to change cookie name
- Using wp_set_auth_cookie for custom user account system
- Should wordpress_logged_in cookie exist while logged out?
- Clearing cookie on logout and session expiration
- WP_Http_Cookie destroys cookie value through urldecode()
- Worpdress PHPSESSID / EU law
- Get restrict content by submitting Gravity Forms
- Website Loads Twice Unnecessarily
- Do I use cookies?
- How to transition cookies from .subdomain.domain.com to .domain.com with minimal impact on users?
- wp_logout action not working
- Hide/Show content based on cookie
- What is cookie “U” from domain “.adsymptotic.com” found on the WordPress page? [closed]
- Serving Cookies From A Different Domain or Sub-Domain
- How to fix samesite attribute in wordpress for chrome errors?
- Secure wordpress_logged_in cookie
- Logout user and delete cookies from the client side?
- Show greetings on first time visitors?
- Unset a Cookie on Successful Gravity Forms form Submission [closed]
- How set a cookie from PHP and get it without refresh
- Why wordpress cookies name contains HASH
- Cookie only detected when visitor is logged in
- Change the user is logged in cookie name
- can we share user login in 2 wordpress installs in 2 subdomains on one server? [duplicate]
- background/font size change and remember
- WordPress cookies
- Modifying request $_COOKIE
- Block google maps from loading until user agrees to cookies with Elementor
- WordPress Keeps Logging Out – What Tests Can I Run to Solve This?
- Need help setting cookies with multiple value [closed]
- Enable WordPress to share cookies between domain.com and sub.domain.com
- Setting Cookies
- How I can share cookies from my dimain to subdomain?
- How to setup cookie free domain for wp-includes?
- WordPress authentication cookie and ajax calls
- After logout browser’s back button into twenty sixteen theme profile
- COOKIE_ID with username appended
- Setting Cookies For Form Autofill
- What are your thoughts on overriding the PHP builtin setcookie() function to control whether or not WP creates cookies
- How to make use of Transient API as cookie
- Issues with set cookie
- Accept or deny cookies – how to?
- How to set a Cookie-Free Domain with WordPress?
- Is it possible to use cookie-free domains in WordPress?
- Passing cookies when using wp_remote_get
- Setting cookies in WP REST API requests
- Detect if authentication is set to “remember” a user being logged on
- Store value in cookie
- WordPress Post Voting – Vote once per IP on entire site
- How to change WordPress cookies to be session-only
- wordpress can’t read a cookie?
- Do I need a Cookie consent on a basic WordPress site?
- Page specific cookie
- will creating a static folder in the root directory serve the purpose of loading the static content from cookieless domain?
- Set cookie with taxonomy name
- Best method to show modal only once
- Cookie with referral URL [closed]
- How to keep a variable in COOKIE or GET query string?
- Cookie Details Requested
- Cookies in template
- Cookie error. No possibility to define my cookie
- Favicon not loading until cookies are accepted?
- can you help review CCCP (Conditional Cookie Content Post) and help to create a block?
- COOKIE_DOMAIN chaos
- Setup cookie on Chrome even without HTTPS
- Change auth_cookie_expiration for specific roles and specific login times
- PHP cookie control does not work correctly
- How can I get an updated cookie in header.php?
- Setting a Custom Cookie in WordPress only for Logged In Customer/User (non-admin)
- How are sites using wordpress hiding wordpress cookies that have “wp” or “wordpress” in the cookie name?
- Correct user session/cookie handling with external site connection in wordpress
- Checking for cookies returns correct result only inside Elementor Editor
- How to save history in the client’s browser without login? [closed]
- Entirely Cookieless WordPress?
- is_user_logged_in() returns different values on different pages
- Why deleting/removing cookies in WordPress does not log me out from admin?
- When ever wordpress home page refreshes the code is not reading the cookie as set anymore
- http_referrer issue when detecting where site comes from and allow if from allowed host
- detect referr page
- Looking to load a different template part on every load/refresh
- Cookie is not set
- Capture and display users name
- Why isn’t my cookie setting in my function?
- WordPress wp-login.php cookie error (WordPress Version 4.2.9)
- Logged In cookie gets saved but not Auth cookie
- set cookies or let system know a user has been on site
- setcookie not working when defined with ‘/’ but working if not defined
- WP Logs me out after updating anything on dashboard
- How to get the id dynamically to store cookies
- WordPress keep logged in after browser close