Woocommerce只读计费字段-选择和单选字段 [英] Woocommerce Readonly Billing Fields - Select and Radio Fields

查看:92
本文介绍了Woocommerce只读计费字段-选择和单选字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了 @zipkundan 建议的解决方案,如下所示:

I've implemented the solution suggested by @zipkundan like this:

    add_action('woocommerce_checkout_fields','customization_readonly_billing_fields',10,1);
function customization_readonly_billing_fields($checkout_fields){
    $current_user = wp_get_current_user();;
    $user_id = $current_user->ID;
    foreach ( $checkout_fields['billing'] as $key => $field ){
        if($key == 'billing_address_1' || $key == 'billing_address_2' || $key == 'billing_first_name' || $key == 'billing_check_business' || $key == 'billing_company_name' || $key == 'billing_last_name' || $key == 'billing_codice_fiscale' || $key == 'billing_vat' || $key == 'billing_address_1' || $key == 'billing_city' || $key == 'billing_state' || $key == 'billing_postcode' || $key == 'billing_phone' || $key == 'billing_email'){
            $key_value = get_user_meta($user_id, $key, true);
            if( strlen($key_value)>0){
                $checkout_fields['billing'][$key]['custom_attributes'] = array('readonly'=>'readonly');
            }
        }
    }
    return $checkout_fields;
}

正常运行,除了billing_state和billing_check_business外。 billing_state是一个选择字段billing_check_business是一个rado字段。关于如何使此代码也适用于select和radio的任何建议?谢谢

and it works correctly except for billing_state and for billing_check_business. billing_state is a select field billing_check_business is a rado field. Any suggestion on how to make this code working also for select and radio? Thanks

推荐答案

add_filter('woocommerce_billing_fields', 'my_woocommerce_billing_fields');
function my_woocommerce_billing_fields($fields)
{
    $fields['billing_first_name']['custom_attributes'] = array('readonly'=>'readonly');
    $fields['billing_last_name']['custom_attributes'] = array('readonly'=>'readonly');
    $fields['billing_address_1']['custom_attributes'] = array('readonly'=>'readonly');
    $fields['billing_address_2']['custom_attributes'] = array('readonly'=>'readonly');
    $fields['billing_postcode']['custom_attributes'] = array('readonly'=>'readonly');
    $fields['billing_city']['custom_attributes'] = array('readonly'=>'readonly');

    return $fields;
}

这篇关于Woocommerce只读计费字段-选择和单选字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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