As per my last tutorial, which showed you how to add a password confirm field to the checkout page, this tutorial falls in the same category but for the register form on the My Account page.
In WooCommerce 2.1 the repeat password fields was removed as it was decided it was easy enough to reset your password with one click should you have gotten in wrong.
If you would still like to add a password confirm field on your register page all you have to do is add the code below to your theme’s functions.php file.
This will add a new field underneath the password field with a label Password Repeat, and then when the customer clicks register it will match the password and password repeat fields against each and and proceed with registration it it matches, or throw an error if it does not match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts. | |
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3); | |
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) { | |
global $woocommerce; | |
extract( $_POST ); | |
if ( strcmp( $password, $password2 ) !== 0 ) { | |
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) ); | |
} | |
return $reg_errors; | |
} | |
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_password2"><?php _e( 'Password Repeat', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input type="password" class="input-text" name="password2" id="reg_password2" value="<?php if ( ! empty( $_POST['password2'] ) ) echo esc_attr( $_POST['password2'] ); ?>" /> | |
</p> | |
<?php | |
} | |
?> |
Hi Gerhard,
Super snipplet. I Try to extend it to use the option in Woocommerce to use password creation. When I like to use it the passwordvalidation is not shown and if I deactivate the option, the field is shown in the register tab on my account site. BTW it works fine with your code for the checkout page.
Thanks a lot
Regards Josef
I use following in my function.php:
if ( ‘no’ === get_option( ‘woocommerce_registration_generate_username’ ) ) :
add_filter(‘woocommerce_registration_errors’, ‘registration_errors_validation’, 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
extract( $_POST );
if ( strcmp( $password, $password2 ) !== 0 ) {
return new WP_Error( ‘registration-error’, __( ‘Passwords do not match.’, ‘woocommerce’ ) );
}
return $reg_errors;
}
add_action( ‘woocommerce_register_form’, ‘wc_register_form_password_repeat’ );
function wc_register_form_password_repeat() {
?>
*
<input type="password" class="input-text" name="password2" id="reg_password2" value="” />
*
<input type="password" class="input-text" name="password2" id="reg_password2" value="” />
<?php
}
//End of the code from Gerhard
endif;
I got fixed.
if ( ‘no’ === get_option( ‘woocommerce_registration_generate_username’ ) ) : – was wrong
Please use
if ( ‘no’ === get_option( ‘woocommerce_registration_generate_password’ ) ) :
instead.
Thanks
Josef
hello
is there a way to add an email confirmation field to the registration screen? is it done by wordpress directly or in woocommerce?
thanks!
User registers
WooCommerce automatically logs them in ……….
How can i stop the auto login until the person has been approved (or denied) by Admin
Hi Gerhard,
I put the above code in my functions.php file and when i went to the my-account page i got the following error:
Warning: Cannot modify header information – headers already sent by (output started at /site/wp-includes/functions.php:3078) in /site/wp-includes/pluggable.php on line 1121
Removing the code from the functions.php file has made no difference. I still get the error. What has changed and where?
Thanks,
Ben
Gerhard, thank you! This is totally awesome…
Nice post but the code you are wanting to have people paste into their functions.php file does not work and is improper syntax.
Hi Cedric
Do you have any idea about the proper code for get this working? I´m not fluent with PHP, more like web designer and i want to get this done for my site.
Thanks a lot.
Awesome THANKS! :3
Thank you Gerhard,
For posting valuable article. But I can not make custom customer login and registration form. I try different methods but not success. I hope you understand my problem .
Waiting your great suggestion.
Sudip Lama
Hi Gerhard
Do you have any idea about the proper code for get this working? I tried with the code that you posted but i got a blank page, i´m currently using WC 2.2.4, the code is different for this version?
Thanks a lot.
Hi Leonardo, try only adding the code between the tags to your file, your functions.php file most likely already have tags like that.
Hi Gerhard
how to customize Registration form in woocommerce my account page, i want to add these fields :
First Name
Last Name
Gender
Email
Password
Retype Password
Thanks a lot
Experience the great taste for yourself order steaks
online. If you are someone who gets your food home delivered, you cause double pollution when the delivery guy makes many
stops to deliver his products to other houses close to you as well.
You wouldn’t have to worry about keeping a diary of your meals because everything is taken care of
to ensure that you are eating low calorie meals every single day.
This code worked perfectly until i updated to Php 7 where it broke 🙁 any ideas?
The answer might be in you error log?
0 Pingbacks
Categories
Top Posts & Pages
Instagram
No Instagram images were found.
Get Email Notifications