For edit woocommerce
(WordPressss plugin) account page fields and make to read-only, easy edit woocommerce/templates/myaccount/form-edit-account.php
file and only add read-only to end of fields tags end (sorry my English and programming is not professional and good)
But for edit woocommerce
checkout page fields and make one, or two and more fields, for example, email field, to read-only, cannot do the previous way
Please help me to do it, I have not idea.
It would be much better if, teach me to do it from functions.php easy and better and durable way (if it is possible).
thank you again
You can use the 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 will check 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 the user. You can apply the same concept for each required fields.
Hope this helps.
Thank You!