• Resolved diffler

    (@diffler)


    Hello!

    If a customer tries to checkout with an email address tied to an existing account, they cannot complete their purchase without logging in. This is bad for conversions.

    Before altering this, I would like to ask why this is the default way to handle this in WooCommerce? Why can’t they just checkout without getting their order tracker OR track it to their existing account even if they haven’t logged in?

    Just trying to understand if there are very good reasons for this and if I shouldn’t change how it works.

    (I have found this piece of code that should make it possible. Any risks in using this? Looks pretty clean to me

    add_action('woocommerce_checkout_process', function () {
        if (!is_user_logged_in() && $_POST['billing_email'] && $_POST['createaccount'] == 1) {
            $user = get_user_by('email', $_POST['billing_email']);
            if ($user) wp_set_current_user($user->ID);
        }
    });

    )

    Thank you!

Viewing 1 replies (of 1 total)
  • Hi @diffler

    Thanks for reaching out!

    The default setting in WooCommerce is designed for security and data consistency. When a customer uses an email address associated with an existing account, WooCommerce prompts them to log in to prevent potential misuse of the account and to ensure that all order history is accurately tracked under the correct account.

    Allowing purchases without login could lead to potential security risks, such as unauthorized use of an email address, and data discrepancies, such as order histories being split across multiple sessions or accounts.

    As for the code snippet you’ve found, it’s crucial to remember that altering the default functionality of WooCommerce can have unintended consequences, and it might not be supported in future updates of WooCommerce. If you decide to proceed, I’d strongly recommend backing up your site and thoroughly testing the changes in a staging environment before implementing them on your live site.

    Furthermore, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Why requiring current users to log in is the default behaviour?’ is closed to new replies.