Auto login after user registration and payment via Stripe

I’ve seen many code snippets online to auto-login the user after completing a form with the User registration add-on. However none of these seem to work after the user returns to the site after payment via Stripe. Is it possible to have the user pay via Stripe, then return to the site (to a ‘thank you’ page) and be auto-logged in?


Hi David. I don’t know of a way to do that when using Stripe Checkout. I will leave this open in case someone else has an idea.

Thanks for your reply Chris.

Would it be possible if I switched to Stripe “Credit Card Field (Elements, SCA-ready)”?
I wonder if it’s then possible because users wont be leaving the site?

I’ve seen code like this online, that claims to login after registration. Is it possible to change the trigger to a ‘payment success’ trigger?

add_action( 'gform_user_registered', 'wpc_gravity_registration_autologin',  10, 4 );
 * Auto login after registration.
function wpc_gravity_registration_autologin( $user_id, $user_config, $entry, $password ) {
	$user = get_userdata( $user_id );
	$user_login = $user->user_login;
	$user_password = $password;
       $user->set_role(get_option('default_role', 'subscriber'));

    wp_signon( array(
		'user_login' => $user_login,
		'user_password' =>  $user_password,
		'remember' => false

    ) );

If the payment is collected on the site, then you have a chance at logging the user in after the form is submitted and they are registered. I am not sure if that code still works, but it’s worth a try, if you collect payment on the site (or you can test the code with a non-payment form, to see if it can work.)

If that code does not work, there are other code solutions posted online, or, you can use this perk from Gravity Wiz:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.