Updated
You can make checkout country dropdown fields disabled (read only) as follows:
add_filter( 'woocommerce_checkout_fields', 'checkout_country_fields_disabled' );
function checkout_country_fields_disabled( $fields ) {
$fields['billing']['billing_country']['custom_attributes']['disabled'] = 'disabled';
$fields['billing']['shipping_country']['custom_attributes']['disabled'] = 'disabled';
return $fields;
}
As disabled select fields doesn't get posted, you need additionally the following duplicated hidden fields with the correct values set in. It will avoid an error notice notifying that country required fields values are empty. So add this too:
// Mandatory for disable fields (hidden billing and shipping country fields with correct values)
add_filter( 'woocommerce_after_checkout_billing_form', 'checkout_country_hidden_fields_replacement' );
function checkout_country_hidden_fields_replacement( $fields ) {
$billing_country = WC()->customer->get_billing_country();
$shipping_country = WC()->customer->get_shipping_country();
?>
<input type="hidden" name="billing_country" value="<?php echo $billing_country; ?>">
<input type="hidden" name="shipping_country" value="<?php echo $shipping_country; ?>">
<?php
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Notes:
You will need to disable shipping calculator in cart page, if it's not done.
If you want to make country dropdown read only in Checkout and in My account Edit Address too, use the following instead:
add_filter( 'woocommerce_billing_fields', 'checkout_billing_country_field_disabled' );
function checkout_billing_country_field_disabled( $fields ) {
$fields['billing_country']['custom_attributes']['disabled'] = 'disabled';
return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'checkout_shipping_country_field_disabled' );
function checkout_shipping_country_field_disabled( $fields ) {
$fields['shipping_country']['custom_attributes']['disabled'] = 'disabled';
return $fields;
}
// Mandatory for disable fields (hidden billing and shipping country fields with correct values)
add_filter( 'woocommerce_after_checkout_billing_form', 'checkout_country_hidden_fields_replacement' );
function checkout_country_hidden_fields_replacement( $fields ) {
$billing_country = WC()->customer->get_billing_country();
$shipping_country = WC()->customer->get_shipping_country();
?>
<input type="hidden" name="billing_country" value="<?php echo $billing_country; ?>">
<input type="hidden" name="shipping_country" value="<?php echo $shipping_country; ?>">
<?php
}