Created
January 18, 2023 16:17
-
-
Save jjmontalban/38cd23743e86b2192d944afbec8f3568 to your computer and use it in GitHub Desktop.
Add password confirmation in Woocommerce register
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
/** | |
* @snippet Añadir confirmación de contraseña en el registro woocommerce | |
* @author @jose64 | |
*/ | |
//1. Verifica que la opción de generar la contraseña automáticamente no esté activada en la configuración de WooCommerce | |
function wc_register_form_password_validation() { | |
if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) { | |
?> | |
<p class="form-row form-row-wide"> | |
<label for="reg_password2"><?php _e( 'Repite la contraseña', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input class="woocommerce-Input woocommerce-Input--text input-text" type="password" class="input-text" name="password2" id="reg_password2" autocomplete="current-password" /> | |
</p> | |
<?php | |
} | |
} | |
add_action( 'woocommerce_register_form', 'wc_register_form_password_validation' ); | |
//2. Valida las contraseñas y define el mensaje de error de validación en la página de registro | |
function register_password_validation($reg_errors, $sanitized_user_login, $user_email) { | |
global $woocommerce; | |
extract( $_POST ); | |
if ( strcmp( $password, $password2 ) !== 0 ) { | |
return new WP_Error( 'registration-error', __( 'Las dos contraseñas no coinciden.', 'woocommerce' ) ); | |
} | |
return $reg_errors; | |
} | |
add_filter('woocommerce_registration_errors', 'register_password_validation', 10,3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment