woocommerce_login_redirect is similar to login_redirect and it has a users parameter. That means you don’t have to use get_current_user_id()
(which was returning 0 when I tested it).
Instead, replace get_current_user_id()
with $user->ID;
.
For example:
function redirect_login_to_tos($redirect, $user) {
$user_id = $user->ID;
$checkout_tos2 = get_user_meta($user_id, 'checkout_tos2', true);
$checkout_tos3 = get_user_meta($user_id, 'checkout_tos3', true);
if($checkout_tos2 != 'agreed' || $checkout_tos3 != 'agreed'){
$redirect="/updated-terms-and-conditions/";
}else{
$redirect="https://wordpress.stackexchange.com/";
}
return $redirect;
}
add_filter('woocommerce_login_redirect', 'redirect_login_to_tos', 10, 2);
Related Posts:
- How do I make a redirect in PHP?
- PHP – redirect https to http and www to non-www
- Redirect to Page after Post Submit
- Calling a method from functions.php on a click of a button
- How to redirect users to custom lostpassword page?
- Showing user ID on user main page from screen options
- Insert code when users come from an specific referer
- How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
- Is Auto Post recognition a WordPress feature? How to turn it off?
- WordPress template_include filter not working properly
- Logout and redirect using the WP Menu
- Issue with foreach on duplicate meta_key’s
- get_usermeta() deprecated in favor of get_user_meta(). But why doesn’t it make use of it?
- Change links automatically to affiliate links
- PHP If user is logged in & on home page redirect
- How to display user nickname (not display name) in PHP template?
- Get all user meta by meta key instead of ID
- Create a new usermeta field for users
- How to get a list of all possible values of a specific user meta key?
- How do I display a user’s previous orders as a select box option on a product?
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- WordPress does not load page.php, return 404.php
- How to use an associative array in post__in with WP_Query?
- 3 blogs same installation, without WP MU
- How to check if a meta value has already been assigned to any user?
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- function to assign user role based on a field from usermeta
- How to upload a file to a folder named after the user_id via plugin
- Creating user status mode in WordPress
- WordPress homepage infinite redirect
- How can I save unique user data on my site? [closed]
- Adding number to date not working [closed]
- Redirect undesirable domain
- How to abort saving data in save_extra_profile_fields function WordPress?
- How do I display the main domain for my WordPress install?
- Let Users Choose Post Categories
- Update user profile information from functions.php
- Problem with login form
- Set Cache-Control header for 301 redirects
- a:0:{} is replaced into database as s:6:”a:0:{}”;
- How to redirect users based on role and content of redirect_to?
- Moving code from theme header to functions.php
- Showing latest post without 301 redirect
- Having Issue on Redirecting With Session in WordPress
- Read array in php?
- Using a $GET parameter from a URL, to redirect to a URL (WordPress)
- Countdown to date function?
- WordPress redirect redirecting too many times or not at all
- Getting users with a specific meta data and then querying their posts?
- How to update and save user metadata on page visits?
- Using Argument from Function to Re-Direct Visitor (WordPress)
- I am receiving a pluggable.php warning sign on my only http:// page
- Where to insert redirect code based on http_referer?
- If Array Values Match Another Array’s Values, Then
- User Meta Value not echoing despite Var_Dump Showing correct string
- Is this a correct usage of ob_start() in my WordPress project?
- How to allow download url redirection only if user logged in WordPress site?
- Shortcode for Listing Users from Meta Value?
- Getting different user data depending on where I use variable
- Adding Author Box Meta Links with Co-Authors
- Get the users that my following users are following
- Comapare get_user_meta value
- WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
- Adding user meta to post meta wp_insert_post() not working
- Get meta_query value by user meta array
- Creating a custom register form
- get_users when from meta key that has serialized values
- How can get all users by current user meta (array)?
- Override 404 when navigating to single php file
- Submit to itself don’t work
- Store stripe info as user_meta
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Updating custom user meta
- redirect 301 with special character like WIX site “#!”
- Updating meta_value in a custom key
- 301 redirect from webpage to wordpress page in the same root
- Submitting my form to the database and then redirecting to payment site
- Limit the number of successful logins
- Get author meta of all writers
- Let users register weight each day and save it in DB
- 3 domains, 1 wordpress install, redirecting and changing domains on live site
- Get permalink for a post from inside WordPress and route to a related site
- Hide a nav menu item based on get_user_meta results
- Redirect users not logged in to the standard login page (and back) from some posts and pages
- Link to external page has wordpress blog-url inside
- How to use multiple 404 Error Pages in WordPress
- A better way to write this php function
- Import users and custom user meta from csv
- How to create a WordPress PAGE in another folder?
- index.php file keeps redirecting to a non-existent index.html file?
- Redirect loop upon installation of my plugin
- wp_login_url always redirects me to wp-admin
- wp-login – unable to redirect user to a custom login url
- Redirect to current URL and append specified URL parameter on unsuccessful login through Elementor login form widget
- Problem with custom user fields default value and retrieval
- Change WordPress Multisite Domain to subfolder
- Redirect WordPress page to the latest created post by the logged in author/user
- Can I redirect media urls (not attachment pages) to the post parent?
- How can I allow a user to add any number of custom user_meta fields on a WordPress front-end page?
- Processing data and redirecting with query string