Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hachesilva/c82688587da7263ff68abd45a1b24b0d to your computer and use it in GitHub Desktop.
Save hachesilva/c82688587da7263ff68abd45a1b24b0d to your computer and use it in GitHub Desktop.
Add confirm password field into WooCommerce registration form
<?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.
*/
function woocommerce_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_filter('woocommerce_registration_errors', 'woocommerce_registration_errors_validation', 10, 3);
function woocommerce_register_form_password_repeat() {
?>
<p class="form-row form-row-wide">
<label for="reg_password2"><?php _e( 'Confirm password', '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
}
add_action( 'woocommerce_register_form', 'woocommerce_register_form_password_repeat' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment