Created
February 7, 2019 06:19
-
-
Save akther80/e217836c880ae67f223bf335c52c8731 to your computer and use it in GitHub Desktop.
Electro v2 - Add confirm password field in Registration Form
This file contains hidden or 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
// ----- 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, $password2 ) !== 0 ) { | |
return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'electro' ) ); | |
} | |
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', 'electro' ); ?> <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 | |
} | |
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.', 'electro' ), 'error' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment