WooCommerce: Pre-select and restrict to one state and city on checkout

Viewed 14700

I'm setting up a store that only sells to one city. I'm trying to figure out how I can restrict the city option to a pre-filled field.

I've already limited the country and using the following code in my functions.php:

add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );

function change_default_checkout_country() {
  return 'PK'; // country code
}

function change_default_checkout_state() {
  return 'SD'; // state code
}

And I've pre-selected the state using the following:

add_filter( 'woocommerce_states', 'bbloomer_custom_woocommerce_states' );

function bbloomer_custom_woocommerce_states( $states ) {
$states['PK'] = array(
'SD' => 'Sindh',
);
return $states;
}

But... Now comes the city and I am lost. I've tried using $fields['billing']['billing_city'] as well as $fields['billing']['billing_city']['value'] to no avail.

I want the customer to be limited to Karachi. I am not very familiar with WooCommerce filters, so I need help on achieving this.

1 Answers
Related