简体   繁体   中英

Removing the password field in woocommerce checkout page

I am trying to remove the password field in the checkout page.

Here is what I have tried (code is in my functions.php theme file) :

// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
     $checkout_fields['account']['required'] = false;

     return $checkout_fields;
}

But it didn't work.

What is the hook for removing the password field in woocommerce checkout page?

Thanks.

The hook woocommerce_default_address_fields is only used for default address fields and not for the account fields.

To make the passwords fields optional you should need using woocommerce_checkout_fields hook, this way:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
     // There is 2 password fields
     fields['account']['account_password']['required']  = false;
     fields['account']['account_password-2']['required'] = false;

     return $fields;
}

To remove those passwords fields you should need to use unset() PHP function this way:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
     unset($fields['account']['account_password']);
     unset($fields['account']['account_password-2']);

     return $fields;
}

But I am not sure that is really possible, as it's something mandatory in WooCommerce checkout process, when you have enabled the option to register in checkout page…

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.


Official Reference: Customizing checkout fields using actions and filters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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