• Resolved svenms

    (@svenms)


    Dears,

    We have problems, when a new user try to register with registration_errors the user is created anyway.
    When a user trys to register and there are missing or wrong fields the user should not be created in the system.

    Photo:
    https://ibb.co/hx0Nj4S

    Please help us how to fix this issue,

    Best regards,

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @svenms,
    Thank you for contacting us, Can you please let us know the plugin you are using for the registration fields.

    Thanks!

    Thread Starter svenms

    (@svenms)

    WIth functions.php code:

    // Field validation
    add_filter( 'registration_errors', 'wedevs_registration_errors', 10, 3 );
    function wedevs_registration_errors( $errors, $sanitized_user_login, $user_email ) {
    
    	if ( empty( $_POST['billing_company'] ) || empty( $_POST['billing_rut'])  ) {
    		$errors->add( 'first_or_last', __( '<strong>ERROR</strong>: missing Billing compny or Billing RUT', 'wedevs' ) );
    	}
    
    	return $errors;
    }
    
    /**
     * Add new register fields for WooCommerce registration.
     *
     * @return string Register fields HTML.
     */
    function wooc_extra_register_fields() {
    	?>
    
    	<p class="form-row form-row-last">
    	<label for="reg_billing_company"><?php _e( 'Razón Social o Nombre de la Empresa', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_company" id="reg_billing_company" value="<?php if ( ! empty( $_POST['billing_company'] ) ) esc_attr_e( $_POST['billing_company'] ); ?>" />
    	</p>
    
    <p class="form-row form-row-last">
    	<label for="reg_billing_company2"><?php _e( 'Giro de la Empresa', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_company2" id="reg_billing_company2" value="<?php if ( ! empty( $_POST['billing_company2'] ) ) esc_attr_e( $_POST['billing_company'] ); ?>" />
    	</p>
    
    	<p class="form-row form-row-wide">
    	<label for="reg_billing_rut"><?php _e( 'Rut', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_rut" id="reg_billing_rut" value="<?php if ( ! empty( $_POST['billing_rut'] ) ) esc_attr_e( $_POST['billing_rut'] ); ?>" />
    	</p>
    <p class="form-row form-row-first">
    	<label for="reg_billing_country"><?php _e( 'País', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_country" id="reg_billing_country" value="<?php if ( ! empty( $_POST['billing_country'] ) ) esc_attr_e( $_POST['billing_country'] ); ?>" />
       </p> 
        
        
    <p class="form-row form-row-first">
    	<label for="reg_billing_state"><?php _e( 'Región', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_state" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_state'] ) ) esc_attr_e( $_POST['billing_state'] ); ?>" />
        </p>
    
    <p class="form-row form-row-wide">
    	<label for="reg_billing_address_1"><?php _e( 'Dirección', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" />
    	</p>
        
    <p class="form-row form-row-first">
    	<label for="reg_billing_city"><?php _e( 'LOCALIDAD / CIUDAD', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_city" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_city'] ) ) esc_attr_e( $_POST['billing_city'] ); ?>" />
    	</p>
        
        <p class="form-row form-row-wide">
    	<label for="reg_billing_phone"><?php _e( 'Teléfono', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
    	</p>
        
    
    	</p>
    	<p class="form-row form-row-first">
    	<label for="reg_billing_web"><?php _e( 'Página Web', 'woocommerce' ); ?> <span class="required">*</span></label>
    	<input type="text" class="input-text" name="billing_web" id="reg_billing_web" value="<?php if ( ! empty( $_POST['billing_web'] ) ) esc_attr_e( $_POST['billing_web'] ); ?>" />
    	</p>
        
        
    	<?php
    }
    
    add_action( 'register_form', 'wooc_extra_register_fields' );

    Hi @svenms,
    The code you have shared above you have added the validation conditions for only 2 fields. You need to add those conditions for the remaining fields as well.
    here is how you can modify it for other fields as well.

    // Field validation
    add_filter( 'registration_errors', 'wedevs_registration_errors', 10, 3 );
    function wedevs_registration_errors( $errors, $sanitized_user_login, $user_email ) {
    
    	if ( empty( $_POST['billing_company'] ) || empty( $_POST['billing_rut'])  ) {
    		$errors->add( 'first_or_last', __( '<strong>ERROR</strong>: missing Billing compny or Billing RUT', 'wedevs' ) );
    	} else if(empty( $_POST['billing_country'] ) ){
    		$errors->add( 'billing_country', __( '<strong>ERROR</strong>: missing Billing Country', 'wedevs' ) );
    	} else if(empty( $_POST['billing_state'] ) ){
    		$errors->add( 'billing_state', __( '<strong>ERROR</strong>: missing Billing State', 'wedevs' ) );
    	}
    
    	
    	return $errors;
    }
    Thread Starter svenms

    (@svenms)

    Correct,

    But a single error activation should be enough to stop Users accountfor been created.
    Currently, if you leave ‘billing_company’ field empty, the message error appears but the user is still created in the system.
    If I disable New User Approve, then the user is no loger created.

    Found the solution here:

    https://ww.wp.xz.cn/support/topic/registration_errors-filter-problem/

    Hi @svenms,
    It’s nice to hear that your issue is resolved.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘New user created even with registration errors’ is closed to new replies.