简体   繁体   English

删除woocommerce结帐页面中的密码字段

[英]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) : 这是我尝试过的(代码在我的functions.php主题文件中)

// 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? 在woocommerce结帐页面上删除密码字段的钩子是什么?

Thanks. 谢谢。

The hook woocommerce_default_address_fields is only used for default address fields and not for the account fields. 钩子woocommerce_default_address_fields仅用于默认地址字段 ,而不用于帐户字段。

To make the passwords fields optional you should need using woocommerce_checkout_fields hook, this way: 要使密码字段为可选,您应该需要使用woocommerce_checkout_fields挂钩,这种方式是:

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: 要删除这些密码字段,您应该需要通过以下方式使用unset() PHP函数:

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… 但是我不确定这是否真的可能,因为当您启用了在结帐页面中注册的选项时,这在WooCommerce结帐流程中是必不可少的……

Code goes in function.php file of your active child theme (or theme) or also in any plugin file. 代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。


Official Reference: Customizing checkout fields using actions and filters 官方参考: 使用操作和过滤器自定义结帐字段

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

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