How to add a confirm password field in woocommerce checkout form?
author
,
Aspirant Programmer

Is there a way to add a confirm password field in woocommerce checkout form?

  • Total 1 Answer
  • 382
Can You answer this question?
author
,
Aspirant Programmer

Presumed, you have enabled the registration setting from admin panel and password field can be seen on checkout form. Now, you need an additional confirm password field in the form, you can use below hooks to add and it will work completely fine:

add_filter( 'woocommerce_checkout_fields' , 'confirm_password_field', 10, 1 );
function confirm_password_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' => __( 'Confirm Password', 'woocommerce' ),
        'required'          => true,
        'placeholder' => _x('Confirm Password', 'placeholder', 'woocommerce'),
        'class' => array('form-row-last')
    );
    return $fields;
}

add_action( 'woocommerce_checkout_process', 'confirm_password_validation' );
function confirm_password_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( __( "Password and confirm password doesn’t match.", "woocommerce" ), 'error' );
    }
}

 

Same way as above you can add multiple checkout form fields and customize the form as per your requirement.