Shrek Shrek - 4 years ago 194
PHP Question

Setting email field read only

Using Woocommerce I've removed the shipping addresses/details from the checkout as they are not required but for logged in users I still want to show the email field but show it so it's not editable:

if ( is_user_logged_in() ) {
// change billing_email to read only
} else {
unset($fields['billing']['billing_email']);
}


how is it I achieve this?

Answer Source

Each field can have custom attributes, stored as an array:

$fields['billing']['billing_email']['custom_attributes'] = array( 'readonly' => 'readonly' );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download