本文介绍了禁用或只读 Woocommerce 中编辑帐户页面中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,编辑帐户详细信息"页面包含以下字段:名字、姓氏、电子邮件地址、当前密码和新密码.

现在我只需要为客户用户禁用名字、姓氏、电子邮件地址字段.我正在使用 Flatsome WP 主题和 Woocommerce 插件.

我该怎么做?

解决方案

更新

对于编辑帐户详细信息"字段(电子邮件字段),您需要编辑 模板文件,因为这些字段是在模板中硬编码的

您必须将 readonly 属性添加到相关的输入字段中,例如在此提取示例中:

<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">

 

官方文档: 通过主题覆盖模板

对于我的帐户 >编辑帐单地址,以下代码将使帐单字段名、姓和电子邮件成为只读

:

add_filter( 'woocommerce_billing_fields', 'readonly_billing_account_fields', 25, 1 );函数 readonly_billing_account_fields ( $billing_fields ) {//只有登录用户的我的帐户帐单地址if( is_account_page() ){$readonly = ['readonly' =>'只读'];$billing_fields['billing_first_name']['custom_attributes'] = $readonly;$billing_fields['billing_last_name']['custom_attributes'] = $readonly;$billing_fields['billing_email']['custom_attributes'] = $readonly;}返回 $billing_fields;}

代码位于活动子主题(或活动主题)的 function.

注意:要在结帐页面上也启用此功能,只需在 if(is_account_page()){ 和右括号 } 之前删除 返回 $billing_fields;.


删除这 3 个字段,您将使用:

add_filter( 'woocommerce_billing_fields', 'remove_billing_account_fields', 25, 1 );函数 remove_billing_account_fields ( $billing_fields ) {//只有登录用户的我的帐户帐单地址if( is_account_page() ){未设置($billing_fields['billing_first_name']);未设置($billing_fields['billing_last_name']);未设置($billing_fields['billing_email']);}返回 $billing_fields;}

代码位于活动子主题(或活动主题)的 function.

Currently the Edit Account Details page have these fields: First Name, Last Name, Email address, Current Password & New Password.

Now I need to disable the First Name, Last Name, Email address fields for customers user only. I am using Flatsome WP theme and Woocommerce plugins.

How can I do this?

解决方案

Update

    <label for="account_first_name"><?

For My account > edit billing address, the following code will make readonly the billing fields first name, last name and email:

add_filter( 'woocommerce_billing_fields', 'readonly_billing_account_fields', 25, 1 );
function readonly_billing_account_fields ( $billing_fields ) {
    // Only my account billing address for logged in users
    if( is_account_page() ){

        $readonly = ['readonly' => 'readonly'];

        $billing_fields['billing_first_name']['custom_attributes'] = $readonly;
        $billing_fields['billing_last_name']['custom_attributes'] = $readonly;
        $billing_fields['billing_email']['custom_attributes'] = $readonly;
    }
    return $billing_fields;
}

Code goes in function.


To remove those 3 fields you will use:

add_filter( 'woocommerce_billing_fields', 'remove_billing_account_fields', 25, 1 );
function remove_billing_account_fields ( $billing_fields ) {
    // Only my account billing address for logged in users
    if( is_account_page() ){
        unset($billing_fields['billing_first_name']);
        unset($billing_fields['billing_last_name']);
        unset($billing_fields['billing_email']);
    }
    return $billing_fields;
}

Code goes in function.

这篇关于禁用或只读 Woocommerce 中编辑帐户页面中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多