Woocommerce 只读计费字段 - 选择和单选字段
Posted
技术标签:
【中文标题】Woocommerce 只读计费字段 - 选择和单选字段【英文标题】:Woocommerce Readonly Billing Fields - Select and Radio Fields 【发布时间】:2019-05-01 15:39:56 【问题描述】:我已经实现了@zipkundan 建议的解决方案,如下所示:
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 的任何建议?谢谢
【问题讨论】:
【参考方案1】: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 只读计费字段 - 选择和单选字段的主要内容,如果未能解决你的问题,请参考以下文章