after adding second password field with this code;
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['account']['account_password-2'] = array(
'label' => __('Confirm Password', 'woocommerce'),
'placeholder' => _x('Confirm Password', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row, form-row-wide'),
'clear' => true,
'type' => 'password',
);
return $fields;
}
then add this code to your functions.php
// 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_password-2'] ) !== 0 ) {
wc_add_notice( __( 'Passwords not match.', 'woocommerce' ), 'error' );
}
}
}