Invalid confirmation password Checkout page
-
Hi there, i enabled the user registration in checkout page but i’m always getting this error Invalid confirmation password also if i set an automatic password (so there isn’t password field at all) and also if i set some code in the functions.php, i tried this, from another topic on this issue.
Any solution?
PS: i can’t switch to default theme and diable all the plugins.
Thanks!
-
Hi
you used default field name for confirm password called
password2
Change it to
ywp_password2
at all of your code that used for confirmation;Tested and work;
Good luck
Great thanks.
I test and i tell you
That’s not working
I updated the code like this// ----- validate password match on the registration page function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) { global $woocommerce; extract( $_POST ); if ( strcmp( $password, $ywp_password2 ) !== 0 ) { return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) ); } return $reg_errors; } add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3); // ----- add a confirm password fields match on the registration page function wc_register_form_password_repeat() { ?> <p class="form-row form-row-wide"> <label for="reg_password2"><?php _e( 'Password Repeat', 'woocommerce' ); ?> <span class="required">*</span></label> <input type="password" class="input-text" name="ywp_password2" id="reg_password2" value="<?php if ( ! empty( $_POST['ywp_password2'] ) ) echo esc_attr( $_POST['ywp_password2'] ); ?>" /> </p> <?php } add_action( 'woocommerce_register_form', 'wc_register_form_password_repeat' ); // ----- Validate confirm password field match to the checkout page function lit_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( __( 'Passwords do not match.', 'woocommerce' ), 'error' ); } } } add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10, 2 ); // ----- Add a confirm password field to the checkout page function lit_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' => __( 'Confirm password', 'woocommerce' ), 'required' => true, 'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' ) ); $checkout->__set( 'checkout_fields', $fields ); } } add_action( 'woocommerce_checkout_init', 'lit_woocommerce_confirm_password_checkout', 10, 1 );
First of all i tried to replace only in the input after also in the if() above but nothing i’m always getting the same error
- This reply was modified 4 years, 8 months ago by Carmine.
Hi
you’re right; I’m sorry, I tested in registration form.You can use this snippet:
// ----- validate password match on the registration page add_filter( 'woocommerce_registration_errors', 'registration_errors_validation', 10, 3 ); function registration_errors_validation( $reg_errors, $sanitized_user_login, $user_email ) { if ( is_checkout() ) return $reg_errors; global $woocommerce; extract( $_POST ); if ( $password!= $ywp_password2 ) return new WP_Error( 'registration-error', __( 'Passwords not match.', 'woocommerce' ) ); return $reg_errors; } // ----- add a confirm password fields match on the registration page add_action( 'woocommerce_register_form', 'wc_register_form_password_repeat' ); function wc_register_form_password_repeat() { ?> <p class="form-row form-row-wide"> <label for="reg_ywp_password2"><?php _e( 'Password Repeat', 'woocommerce' ); ?> <span class="required">*</span></label> <input type="password" class="input-text" name="ywp_password2" id="ywp_password2" value="<?php if ( ! empty( $_POST['ywp_password2'] ) ) echo $_POST['ywp_password2'] ; ?>" /> </p> <?php } // ----- Validate confirm password field match to the checkout page add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10 ); function lit_woocommerce_confirm_password_validation( $posted ) { $checkout = WC()->checkout; if ( ! is_user_logged_in() && $checkout->must_create_account ) if ( $posted['account_password']!=$posted['ywp_password2'] ) wc_add_notice( 'error', 'error' ); } // ----- Add a confirm password field to the checkout page add_action( 'woocommerce_checkout_init', 'lit_woocommerce_confirm_password_checkout', 10, 1 ); function lit_woocommerce_confirm_password_checkout( $checkout ) { if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { $fields = $checkout->get_checkout_fields(); $fields['account']['ywp_password2'] = array( 'type' => 'password', 'label' => __( 'Confirm password', 'woocommerce' ), 'required' => true, 'placeholder' => _x( 'Confirm Password', 'placeholder', 'woocommerce' ) ); $checkout->__set( 'checkout_fields', $fields ); } }
- This reply was modified 4 years, 8 months ago by Hamid Reza Yazdani.
Thanks a lot for your time, i tried but the error still here.
Thanks for real
you’re welcome
If you copy/paste entire of my code and not working, please replace this function
// ----- Validate confirm password field match to the checkout page add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10 ); function lit_woocommerce_confirm_password_validation( $posted ) { $checkout = WC()->checkout; if ( ! is_user_logged_in() && $checkout->must_create_account ) if ( $posted['account_password']!=$posted['ywp_password2'] ) wc_add_notice( 'error', 'error' ); }
with this one:
// ----- Validate confirm password field match to the checkout page add_action( 'woocommerce_after_checkout_validation', 'lit_woocommerce_confirm_password_validation', 10 ); function lit_woocommerce_confirm_password_validation( $posted ) { $checkout = WC()->checkout; var_dump( $posted ); if ( ! is_user_logged_in() && $checkout->must_create_account ) if ( $posted['account_password']!=$posted['ywp_password2'] ) wc_add_notice( 'error', 'error' ); }
and check values in your browser’s console;
No, i’m sorry it’s not working and i also have a password repeat field above the registration form in the account page.
By the way i can share with you the console results.
EDIT: The strange thing is in the console i have `[“account_password”]=>
string(4) “pass”
[“ywp_password2”]=>
string(4) “pass”`
Wich is correct, but i still see the error message"result":"failure","messages":"<ul class=\"woocommerce-error\" role=\"alert\">\n\t\t\t<li>\n\t\t\tInvalid confirmation password\t\t<\/li>\n\t<\/ul>\n","refresh":false,"reload":false}
Ok
Based on my code if you have error in the registration form in the account page should show to you:
Passwords not match.
and if you have error in checkout page show:
error
message,
But your error message isInvalid confirmation password
Please review your codes and find the
Invalid confirmation password
expression in your theme, translation files and plugins Because my code work fine on localGood luck
- This reply was modified 4 years, 8 months ago by Hamid Reza Yazdani.
Ok got it!
I will follow your advice, thanks a lot!!
Have a nice day!
well done
You’re welcome
- The topic ‘Invalid confirmation password Checkout page’ is closed to new replies.