Why does is_user_logged_in() return false after redirect from another site?

Question

I am developing a WordPress site that redirects to an external payment gateway after a user registers for the site. After the user makes a payment the user is redirected to a page to complete their sign up.

Here is the code used for the redirect:

$login_data = array();
$login_data['user_login'] = $email;
$login_data['user_password'] = $password;
$login_data['remember'] = true;
$user = wp_signon($login_data);
if(!is_wp_error($user)){
    wp_set_current_user( $user->ID, $email );
    wp_set_auth_cookie( $user->ID, true, false );
    wp_redirect("https://another_payment_gateway.com");
    exit;
}

The user is redirected and fills out the payment form. Upon success the user is redirected to a landing page. If they are not logged in they are shown a dialog for non logged in users.
Here is the code on that page:

if(is_user_logged_in()){
  $user = wp_get_current_user();
  //code for logged in users
}else{
  //message for non logged in users 
}

If I go to the account page it is shown that the user is logged in. But when redirected from a different site is_user_logged_in() returns false.
Any insight into this issue would be much appreciated.

0
, , frank Collins 3 years 2019-11-18T20:14:53-05:00 0 Answers 119 views 0

Leave an answer

Browse
Browse