如何在 WooCommerce 的注册页面上创建密码和确认密码 [英] How to create a password and confirm password on register page on WooCommerce

查看:153
本文介绍了如何在 WooCommerce 的注册页面上创建密码和确认密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 WooCommerce 开发.我在注册页面上,输入电子邮件并单击按钮后,我将通过电子邮件获取密码.

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?

推荐答案

要禁用创建新帐户时自动生成密码,必须禁用创建帐户时,自动生成一个WooCommerce 管理页面中的帐户密码选项.

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.

为此,请转至 WooCommerce >设置 >帐户和隐私:

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

您可以在此处找到更多信息:WooCommerce- 帐户和隐私设置.

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

这篇关于如何在 WooCommerce 的注册页面上创建密码和确认密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆