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