简体   繁体   English

添加确认email地址字段注册Woocommerce

[英]Add confirm email address field registration Woocommerce

There is any way to add a confirm email address field on Wooocommerce registration?有什么方法可以在 Wooocommerce 注册时添加确认 email 地址字段?

Thanks谢谢

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.phpwp-content/plugins/woocommerce/templates/myaccount/form-login.php文件复制到您的主题文件夹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...*Email address字段下添加下面的代码..如果您还没有编辑文件..那么它是line number 88 ,之后你必须把它...

Woocommerce 注册表格

    <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..添加验证...检查 Email 并确认 Email 是否相同。

     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 );
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' );
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM