Awwwards
TopDesignKing

Email & Password Confirmation

When the customers sign up/register for an account, it’s usually because of two things; easier/ faster checkout process and discounts/other perks. While there’s nothing wrong with that — the problem starts when creating the account and choosing the password.

Customer fills in his/her details as normal but makes a typing mistake. All of the sudden, everything goes wrong. No order email received. Maybe it went to someone else? This can happen to anyone, and by default there is no fix in the system.

This comes down to having your system highlighting what went wrong and asking the customer to correct it.

// password confirmation
add_action( 'woocommerce_checkout_init', 'weszty_woocommerce_confirm_password_checkout', 10, 1 );
function weszty_woocommerce_confirm_password_checkout( $checkout ) 
    if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
        $fields = $checkout->get_checkout_fields();
        $fields['account']['account_confirm_password'] = array(
            'type'              => 'password',
            'label'             => esc_html__( 'Confirm password', 'woocommerce' ),
            'required'          => true,
            'placeholder'       => esc_html_x( 'Confirm Password', 'placeholder', 'woocommerce' )
        );
        $checkout->__set( 'checkout_fields', $fields );
    } 
}

add_action( 'woocommerce_after_checkout_validation', 'weszty_woocommerce_confirm_password_validation', 10, 2 );
function weszty_woocommerce_confirm_password_validation( $posted ) {
    $checkout = WC()->checkout;
    if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) {
        if ( strcmp( $posted['account_password'], $posted['account_confirm_password'] ) !== 0 ) {
            wc_add_notice( esc_html__( 'Passwords do not match.', 'woocommerce' ), 'error' );
        } 
    } 
}

// email confirmation
add_filter( 'woocommerce_checkout_fields' , 'weszty_add_email_verification_field_checkout' );
function weszty_add_email_verification_field_checkout( $fields ) {
    $fields['billing']['billing_email']['class'] = array('form-row-first');
    $fields['billing']['billing_em_ver'] = array(
        'label'     => esc_html__( 'Email Address Verification', 'woocommerce' ),
        'required'  => true,
        'class'     => array('form-row-last'),
        'clear'     => true
    );
    return $fields;
}

add_action( 'woocommerce_checkout_process', 'weszty_matching_email_addresses' );
function weszty_matching_email_addresses() { 
    $email1 = $_POST['billing_email'];
    $email2 = $_POST['billing_em_ver'];
    if ( $email2 !== $email1 ) {
        wc_add_notice( esc_html__( 'Your email addresses do not match', 'woocommerce' ), 'error' );
    } 
}

?>

Don't be weird.

Would you like more information or do you have a question?

scroll
10%
Drag View Close play