add_filter( 'woocommerce_checkout_fields' , 'add_confirm_password_checkout_field', 10, 1 );
function add_confirm_password_checkout_field( $fields ) {
if ( get_option( 'woocommerce_registration_generate_password' ) != 'no' )
return $fields;
$fields['account']['account_password']['class'] = array('form-row-first');
$fields['account']['account_password-2'] = array(
'type' => 'password',
'label' => __( 'Password confirmation', 'woocommerce' ),
'required' => true,
'placeholder' => _x('Confirmation', 'placeholder', 'woocommerce'),
'class' => array('form-row-last'),
'label_class' => array('hidden')
);
return $fields;
}
add_action( 'woocommerce_checkout_process', 'confirm_password_checkout_validation' );
function confirm_password_checkout_validation() {
if ( ! is_user_logged_in() && ( WC()->checkout->must_create_account || ! empty( $_POST['createaccount'] ) ) ) {
if ( strcmp( $_POST['account_password'], $_POST['account_password-2'] ) !== 0 )
wc_add_notice( __( "Passwords doesn’t match.", "woocommerce" ), 'error' );
}
}