Woocommerce只读计费字段 [英] Woocommerce Readonly Billing Fields

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

问题描述



我需要将结算地址字段设置为结算地址字段,只读'以避免客户取代放置在那里的信息...但我不知道如何/在哪里做...



是否有可能?

解决方案

在您的主题的function.php文件中添加以下代码:

  ADD_ACTION( 'woocommerce_checkout_fields', 'customization_readonly_billing_fields',10,1); 
函数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_value = get_user_meta($ user_id,$ key,true);
if(strlen($ key_value)> 0){
$ checkout_fields ['billing'] [$ key] ['custom_attributes'] = array('readonly'=>'readonly');
}
}
}
返回$ checkout_fields;





该函数检查地址字段是否有值(例如,如果指定了地址),如果它有价值,则使该字段只读。否则,将这些字段打开以为用户添加数据。
希望这有助于。


I have some e-commerce website where the customer billing address is predefined on the back-end.

I need to set the "Billing Address" fields as 'readonly' to avoid the customer to replace the information placed there... but i don´t know how/where to do it...

Is it possible?

解决方案

Put following code in your theme's "function.php" file.

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_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;
}

This function checks if the address fields have value (i.e. if the address is specified), and if it has value, makes the field/s readonly. Else keeps the fields open to add data for user. Hope this helps.

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

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