Before a checkout is submitted and begins processing, all of the data is passed through this filter.
This let’s you modify any of the checkout fields before they go through the usual WC flow.
Here, we are grabbing the submitted email address and checking if the user already has an account.
If they do, we are making sure they are not trying to create an account which is where WC will crack the dummy.
Hi, could you please share the code snippet for “If the typed email address matches an account, a small field will appear below the email address input asking them if they want to log in.”? 🙂 Thanks.
I have actually done exactly that in my own website, I will write it out here Php as follows: /** * * Validate email input via ajax * */ add_action(‘wp_ajax_validate_email’, ‘validate_email_input’); add_action(‘wp_ajax_nopriv_validate_email’, ‘validate_email_input’); function validate_email_input() { // Don’t do anything if they are logged in if ( is_user_logged_in() ) : echo ”; endif; global $wpdb; $email = $_POST[‘billing_email’]; if ( email_exists( $email ) ) { echo ‘ Looks like you\’ve already got an account. Click here to login ‘; } else { echo ‘false’; } exit; } Javascript as follows: jQuery(document).ready(function() { $(‘input[name=billing_email]’).change(function() { var input_value = $(this).val(); $.post( validateEmail.ajaxurl,… Read more »
This is just what i am after. We have an issue with people not logging in and then trying to complete the cart and of course they get the small error message about email already exists, but they don’t see it.
Where are you adding this code? in Functions.php?Thanks
Alastair
Hi Alastair, yes correct you can add it to functions.php
If you run into any dramas let me know 🙂
Thanks, Chris
A site that was working perfectly now shows “An account is already registered with your email address. Please log in.” for new emails that have not been used before. The snippet for functions.php has no effect. Any ideas what could be the issue?
Hmmmmmm could be many things If the snippet is not working it may be overridden elsewhere, which you can adjust by changing the priority which is the number”10″ in the snippet. Higher number higher priority, try changing 10 to 1000. I would be surprised if that worked though. If it’s definitely new email addresses causing the issue when placing an order then that’s a proper bug – there is no way that would be accidentally happening. This process only occurs (and again, we’re talking about people placing orders) when you’ve got your WC settings configured to create an account at… Read more »