skip to Main Content

There is any way to add a confirm email address field on Wooocommerce registration?

Thanks

2

Answers


  1. There are several ways… Simplest way is to add a new field to registration field and then validate the field when form submitted. Follow this….

    1. Copy wp-content/plugins/woocommerce/templates/myaccount/form-login.php file over to your theme folder wp-content/themes/your-theme/woocommerce/myaccount/form-login.php
    2. Add below code right under *Email address field.. if you have not edited the file yet.. then it’s line number 88 where after you have to put it…

    Woocommerce Regisration Form

        <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
           <label for="confirm_reg_email"><?php esc_html_e( 'Confirm Email address', 'woocommerce' ); ?>&nbsp;<span class="required">*</span></label>
           <input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="confirm_email" id="confirm_reg_email" autocomplete="email" value="<?php echo ( ! empty( $_POST['confirm_email'] ) ) ? esc_attr( wp_unslash( $_POST['confirm_email'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?>
        </p>
    
    1. Add Validation… Check if Email & Confirm Email is same value..

      function so_61352749_validate_confirm_email_register_field( $username, $email, $validation_errors ) {
      
        // Confirm email is set but empty
        if ( !isset( $_POST['confirm_email'] ) ) {
           $validation_errors->add( 'confirm_email_error', __( '<strong>Error</strong>: Confirm Email is required!', 'woocommerce' ) );
         }
      
         if ( isset( $_POST['confirm_email'] ) && $_POST['confirm_email'] !== $_POST['email'] ) {
           $validation_errors->add( 'confirm_email_error', __( '<strong>Error</strong>: Confirm Email is not matched!', 'woocommerce' ) );
         }
      
         return $validation_errors;
      }
      
      add_action( 'woocommerce_register_post', 'so_61352749_validate_confirm_email_register_field', 10, 3 );
      
    Login or Signup to reply.
  2. add_filter( 'woocommerce_checkout_fields' , 'codeithub_add_email_verification_field_checkout' );
       
    function codeithub_add_email_verification_field_checkout( $fields ) {
      
    $fields['billing']['billing_email']['class'] = array( 'form-row-first' );
      
    $fields['billing']['billing_em_ver'] = array(
        'label' => 'Confirm mail Address',
        'required' => true,
        'class' => array( 'form-row-last' ),
        'clear' => true,
        'priority' => 999,
    );
      
    return $fields;
    }
      
      
    add_action('woocommerce_checkout_process', 'codeithub_matching_email_addresses');
      
    function codeithub_matching_email_addresses() { 
        $email1 = $_POST['billing_email'];
        $email2 = $_POST['billing_em_ver'];
        if ( $email2 !== $email1 ) {
            wc_add_notice( 'Your email addresses do not match', 'error' );
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search