All checkout fields read-only
-
Hello,
Im looking to make all fields read-only on my checkout page. The ‘billing_first_name’ and ‘billing_last_name’ are working well now but I have two other fields.
Their ID’s are ‘billing_email’ and ‘company_name’ (custom field). Unfortunately when I use those, it isn’t working. How can I make all fields read-only? I’m not sure how to combine it, or adjust it to make it work.
Thank you ??
// MAKE CHECKOUT FIELDS READ-ONLY
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_first_name’ || $key == ‘billing_last_name’){
$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;
}screenshot: https://imgur.com/a/yCPs2i9
- The topic ‘All checkout fields read-only’ is closed to new replies.