Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce 2.1 Add confirm password option at checkout
<?php
// place the following code in your theme's functions.php file
// Add a second password field to the checkout page.
add_action( 'woocommerce_checkout_init', 'wc_add_confirm_password_checkout', 10, 1 );
function wc_add_confirm_password_checkout( $checkout ) {
if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
$checkout->checkout_fields['account']['account_password2'] = array(
'type' => 'password',
'label' => __( 'Confirm password', 'woocommerce' ),
'required' => true,
'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' )
);
}
}
// Check the password and confirm password fields match before allow checkout to proceed.
add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 );
function wc_check_confirm_password_matches_checkout( $posted ) {
$checkout = WC()->checkout;
if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) {
if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) {
wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' );
}
}
}
?>
@SukcesStrony

This comment has been minimized.

Copy link

@SukcesStrony SukcesStrony commented Jun 1, 2016

Works great. An improvement would be if JavaScript would validate the equality before submission.

@jay7793

This comment has been minimized.

Copy link

@jay7793 jay7793 commented Jun 18, 2016

Cool. Thank you very much.

@planetwebsolutions

This comment has been minimized.

Copy link

@planetwebsolutions planetwebsolutions commented Jul 12, 2016

Thank You very much

@JonathanVandal

This comment has been minimized.

Copy link

@JonathanVandal JonathanVandal commented Aug 22, 2016

How can we render placeholder and label multilingual ?

@nickkaufmann

This comment has been minimized.

Copy link

@nickkaufmann nickkaufmann commented Sep 28, 2016

Many thanks! Exactly what i was looking for. works like a charm

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 22, 2017

I'm not getting the passwords to validate each other. You can type in two different passwords and it allows someone to checkout. Anyone know how to fix?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 22, 2017

I was using stripe modal checkout, the popup that takes the credit card, when I turned that off and allowed the user to enter cc number directly on site then it worked.

@neilgee

This comment has been minimized.

Copy link

@neilgee neilgee commented May 12, 2017

Stopped working for me in WC 3 - passwords so not match error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.