0

I want to achieve that when the user registers on my website, I send him to a specific page, and without automatically logging in.

When we do not register on a WordPress site, we are registered and sent an email to add a password, since I have it configured in the WooCommerce preferences:

WooCommerce => Accounts and Privacy. 

enter image description here

Searching, I came across a function that ensures that when the user enters their email in the registration input, they are not automatically logged in. Firstly, when doing this, it took me to the page that I have assigned, where I explain to the user to check his email, but I have discovered that the WordPress email for the user to add a password is not arriving.

This prevents the user from logging in, even though they successfully logged into the WordPress dashboard. See the function that it uses and that now prevents the mail from being sent to the user to establish the password.

How can I ensure that the user does not log in automatically and that the mail arrives to the user?

Can I get it by modifying this function or do I need another way to do it?

function redirect_after_register() {

wp_logout();

wp_redirect( home_url("sigue-las-instrucciones") );

exit();

}

add_action('user_register', 'redirect_after_register');

They told me that maybe it could be that the priority of the hook breaks the session before sending the mail, and try to delay it with this advice:

add_action('user_register', 'redirect_after_register', 99);

But it doesn't work either, the email to add a password does not reach the user

I have also tried several plugins to check (Email Log , Check & Log Email ) the Log of the emails and they do not show any output message

1 Answer 1

1

Is it possible that your email address in Settings, General is not correct? Or, could the email address have a domain that doesn't match the site domain? Some mail servers don't like to deliver mail from example.com when the sender email is [email protected] .

I would set the admin's email address to an address on the site domain, creating the email account if needed. Then look in the email client for your domain (via your Control Panel, for example) to see if the email arrives there. I'd also send an email to that domain account from another email service to see if it arrives.

If you have a forwarder set for that email account, make sure that your mail records are set correctly for the domain. Ask your hosting support for help with that.

3
  • Thanks for your reply. the configuration that I have in the mail is the one that comes by default in WordPress. If we remove the function I have to prevent automatic login ( redirect_after_register), everything works fine and the mail is sent to the user who registers. But I need to prevent automatic login, and mail to the user to set a password. This is what I want to achieve, is there a way to do it?
    – Estudiante
    Commented Jan 19, 2023 at 21:55
  • 1
    To prevent automatic login, it appears you need to 'destroy' the WP session. Perhaps this question and it's answers will help: wordpress.stackexchange.com/q/385333/29416 Commented Jan 19, 2023 at 23:12
  • Thanks for the support @RickHellwel I've done tests and finally got it with the function from the first answer,(function wc_custom_registration_redirect()) I think you can edit your answer and I'll accept it. I don't know if you can mark my question as Duplicate, I'm not really asking the same question, but one of the answers is useful for me. Thank you for spending part of your time
    – Estudiante
    Commented Jan 20, 2023 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.