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
- 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?
- 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?
- 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?
- 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
- Adding number to date not working [closed]
- Redirect undesirable domain
- How to abort saving data in save_extra_profile_fields function WordPress?
- Let Users Choose Post Categories
- Update user profile information from functions.php
- a:0:{} is replaced into database as s:6:”a:0:{}”;
- Showing latest post without 301 redirect
- Having Issue on Redirecting With Session in WordPress
- Read array in php?
- WordPress redirect redirecting too many times or not at all
- Getting users with a specific meta data and then querying their posts?
- 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?
- 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
- Redirect to current user page upon link click
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- Uses for function: wp_update_user
- Writing a link cloaking plugin
- WordPress permalink issue
- 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
- User meta needed in query is serialized – how to unserialize safely?
- 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
- Right way to display the_author_meta fields?
- WordPress Redirect / Add_Rewrite_Rule – Non Index.php Page
- Adding user meta to post meta wp_insert_post() not working
- 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 “#!”
- 3 domains, 1 wordpress install, redirecting and changing domains on live 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
- 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