How to create a password and confirm password on register page on WooCommerce

点点圈 提交于 2021-01-29 06:14:03

问题


I am learning WooCommerce development. I am on the register page and after entering the email and click on the button the I am getting the password on email.

Now my issue is, I don't want an email for a password. I have created the register page with the password and confirm the password field.

I want can enter their own there instead of getting the email on this password.

function woocom_extra_register_fields() {
    ?>
    <p class="form-row form-row-wide mb-4">
        <label for="reg_billing_password" class="text-uppercase"><?php _e('Password', 'woocommerce' ); ?><span class="required">*</span></label><input type="password" class="input-text form-control" name="billing_password" id="reg_billing_password" value="<?php if ( ! empty( $_POST['billing_password'] ) ) esc_attr_e( $_POST['billing_password'] ); ?>" placeholder="Password" />
    </p>
    
    <p class="form-row form-row-wide">
        <label for="reg_billing_confirmpassword" class="text-uppercase"><?php _e('Confirm Password', 'woocommerce'); ?><span class="required">*</span></label><input type="password" class="input-text form-control" name="billing_confirmpassword" id="reg_billing_confirmpassword" value="<?php if ( ! empty( $_POST['billing_confirmpassword'] ) ) esc_attr_e( $_POST['billing_confirmpassword'] ); ?>" placeholder="Confirm Password"/>
    </p>
    <?php
}
    
add_action('woocommerce_register_form', 'woocom_extra_register_fields');
    
function woocom_validate_extra_register_fields( $username, $email, $validation_errors )
{
    if (isset($_POST['billing_password']) && empty($_POST['billing_password']) ) 
    {
        $validation_errors->add('billing_password_error', __('Password is required!', 'woocommerce'));
    }
    
    if (isset($_POST['billing_confirmpassword']) && empty($_POST['billing_confirmpassword']) ) 
    {
        $validation_errors->add('billing_confirmpassword_error', __('Confirm password is required!', 'woocommerce'));
    }
    return $validation_errors;
}
    
add_action('woocommerce_register_post', 'woocom_validate_extra_register_fields', 10, 3);
    
function woocom_save_extra_register_fields($customer_id) {
    
    if (isset($_POST['billing_password'])) 
    {
        update_user_meta($customer_id, 'billing_password', sanitize_text_field($_POST['billing_password']));
    }
    
    if (isset($_POST['billing_confirmpassword'])) 
    {
        update_user_meta($customer_id, 'billing_confirmpassword', sanitize_text_field($_POST['billing_confirmpassword']));
    }
}
    
add_action('woocommerce_created_customer', 'woocom_save_extra_register_fields');

Would you help me out with this issue?


回答1:


To disable the automatic generation of the password when a new account is created, you must disable the When creating an account, automatically generate an account password option from the WooCommerce admin page.

To do this, go to WooCommerce > Settings > Accounts & Privacy:

You can find more information here: WooCommerce - Accounts & Privacy Settings.



来源:https://stackoverflow.com/questions/65937075/how-to-create-a-password-and-confirm-password-on-register-page-on-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!