WooCommerce – Redirecting a User after They’ve Reset Their Password

I’m setting up a WooCommerce shop for a client and he has requested that the user be redirected back to the login form after the reset password form has been submitted.

Is this possible? Which function controls this?

Read More

Thanks in advance.

Related posts

Leave a Reply

3 comments

  1. A much cleaner solution is to redirect using the woocommerce_customer_reset_password action:

    function woocommerce_new_pass_redirect( $user ) {
      wp_redirect( get_permalink(woocommerce_get_page_id('myaccount')));
      exit;
    }
    
    add_action( 'woocommerce_customer_reset_password', 'woocommerce_new_pass_redirect' );
    

    This code can be placed in functions.php.

  2. Someone asked me about doing this and I think I’m going to talk them out of it, but here’s what I came up with so that you could see the message and then be redirected in 5 seconds. Add a message/link to let them know you’ll be redirecting. Plus, this will last through a WooCommerce upgrade if you add the template file to your theme

    Add the form-lost-password.php template file to your theme and add the following code:

            if ( $_GET[reset] = true && ( 'lost_password' == $args['form']) ) {
                $my_account_url = get_site_url() . '/my-account';
                echo "<script>window.setTimeout(function(){window.location.replace('$my_account_url')}, 5000)</script>";
            }
    

    If you dont want the time delay get rid of the window.setTimeout() and just use window.location.replace(‘$my_account_url’).

  3. I’m just facing the same question. I think the function that controls this is in the file woocommerce/includes/class-wc-form-handler.php. I changed the following line:

    wp_redirect( add_query_arg( 'reset', 'true', remove_query_arg( array( 'key', 'login' ) ) ) );
    

    with

    wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
    

    With that change, you get redirected to the my-account page, where the customer can log in, but of course there are two problems doing that:

    1. The customer gets no message the the password recovery was successful
    2. Doing a WooCommerce update, the file gets overwritten with the original file

    Would be great, if someone could come up with a “update-secure” solution.

    Best regards
    Christoph