I have added custom cities to Woocommerce checkout and each city represents a rate. However, I would like to have a dropdown of cities in the shipping calculator as I have done with the checkout page.
The city field in the shipping calculator is a text field. Currently, I have been only able to change the city field to select at the checkout using this code below:
// Change "city" checkout billing and shipping fields to a dropdown
add_filter('woocommerce_checkout_fields', 'override_checkout_city_fields');
function override_checkout_city_fields($fields) {
// Define here in the array your desired cities (Here an example of cities)
$option_cities = array(
'' => __('Select your city'),
'City A' => 'City A',
'City B' => 'City B'
);
$fields['shipping']['shipping_city']['type'] = 'select';
$fields['shipping']['shipping_city']['options'] = $option_cities;
return $fields;
}
I tried using this tutorial method but it didn't work
<?php
// Ensure to get the correct value here. This __get( 'shipping_area' ) is based on how the Advanced Checkout Fields plugin would work
$current_area = WC()->customer->__get( 'shipping_area' );
?>
<p>
<select name="calc_shipping_area" id="calc_shipping_area">
<option value=""><?php _e( 'Select a area…', 'woocommerce' ); ?></option>
<option value="alpha" <?php selected( $current_area, 'alpha' ); ?>>Alpha</option>
<option value="beta" <?php selected( $current_area, 'beta' ); ?>>Beta</option>
<option value="charlie" <?php selected( $current_area, 'charlie' ); ?>>Charlie</option>
</select>
</p>
Any hep is appreciated.