Make readonly/disabled some WooCommerce checkout fields for registered customers

59 Views Asked by At

In WooCommerce, I would like to allow the country and the city selection only to new customers that haven't placed an order yet. But for customers that have already placed an order once and have yet a selected city and country, those fields should be read-only, and customer should not be able to make changes to it on the payment page (from the user's side).

I tried using the following code:

add_filter('woocommerce_checkout_fields', 'readonly_billing_country_select_field');
function readonly_billing_country_select_field( $fields ) {
     $fields['billing']['billing_country']['custom_attributes'] = array( 'disabled' => 'disabled' );

     return $fields;
}

but unfortunately, it makes the country list read-only for all users, whether they are registered or not!

0

There are 0 best solutions below