问题
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