Especially for B2B sites, it’s likely that customers are managed by the store admin and are not allowed to change their billing/shipping address unless they request to update it.
But even if you’re simply curious, there is a way to turn each checkout field into read-only inputs. In this way, the saved billing and shipping address will load, and the logged in customer won’t be able to change any data before checkout.
A little note: country and state are dropdowns, and this means adding the “readonly” attribute won’t stop you from changing the selected value. However, if we turn all fields to input type “text”, this problem will go away. And this is why you find two statements in the snippet below; first we turn the field into a text input, and then we make it read-only.
Enjoy!
PHP Snippet: Add “readonly” Attribute To The WooCommerce Checkout Billing & Shipping Fields
/**
* @snippet Read-only Billing & Shipping @ Woo Checkout
* @tutorial Get CustomizeWoo.com FREE
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 8
* @community Join https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_checkout_fields', 'bbloomer_checkout_fields_readonly', 9999 );
function bbloomer_checkout_fields_readonly( $fields ) {
foreach ( $fields['billing'] as $field_key => $field_atts ) {
$fields['billing'][$field_key]['type'] = 'text';
$fields['billing'][$field_key]['custom_attributes'] = array( 'readonly' => 'readonly' );
}
foreach ( $fields['shipping'] as $field_key => $field_atts ) {
$fields['shipping'][$field_key]['type'] = 'text';
$fields['shipping'][$field_key]['custom_attributes'] = array( 'readonly' => 'readonly' );
}
return $fields;
}