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
- 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
- Change links automatically to affiliate links
- PHP If user is logged in & on home page redirect
- Get all user meta by meta key instead of ID
- How do I display a user’s previous orders as a select box option on a product?
- 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 can I save unique user data on my site? [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
- 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?
- Getting users with a specific meta data and then querying their posts?
- Using Argument from Function to Re-Direct Visitor (WordPress)
- Where to insert redirect code based on http_referer?
- 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?
- Adding Author Box Meta Links with Co-Authors
- Get the users that my following users are following
- PHP Redirect condition
- Edit Account – read and write to MySQL
- Manually Create PHP Page For A Redirect
- Uses for function: wp_update_user
- Writing a link cloaking plugin
- WP insert post Redirect after function has executed
- Update user repeater meta (ACF) with another user meta field value
- Create condition for Author bio Social Links
- How to redirect non logged in mobile users to page on same site?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Download file and redirect to page or vice versa
- How to store checkbox data for individual users?
- Add more user roles to a PHP logout redirect function [closed]
- How do I Populate a Table Field with User Meta Data?
- 404 on old link after changing post url
- How to add and subtract user meta values after post meta update
- how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- WordPress on Ubuntu – “File not Found” for home.php – Trying to Redirect to Root Folder
- Usermeta data unserialize, extract and display in table in WordPress
- Change user metadata on registration (show_admin_bar_front = false)
- Infinite loop when logging out using custom login form
- Export WordPress User Meta to CSV/Excel
- Updating User Profile information removes image
- Display current user metadata on WordPress page
- WordPress: Redirect Main Site to Subsite in Multisite Where user is NOT logged in
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Get user by meta data key and velue
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Update an additional user meta field with a string
- Add another role to a user when they click a button?
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- not able to access $_POST on backend profile update
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- Right way to display the_author_meta fields?
- WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
- 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)?
- Submit to itself don’t work
- Store stripe info as user_meta
- redirect 301 with special character like WIX site “#!”
- 301 redirect from webpage to wordpress page in the same root
- Limit the number of successful logins
- Get author meta of all writers
- 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
- How to use multiple 404 Error Pages in WordPress
- A better way to write this php function
- How to create a WordPress PAGE in another folder?
- 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
- Problem with custom user fields default value and retrieval
- 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?
- Processing data and redirecting with query string