City Select for WooCommerce. Show a dropdown select as the cities input.
WooCommerce uses a text input for the customers to enter the city or town. With this plugin you can provide a list of cities to be shown as a select dropdown.
This will be shown in checkout pages, edit addresses pages and shipping calculator if it’s configured that way.
A list of cities has to be loaded in the functions.php file (the plugin already includes cities from some countries).
Use wc_city_select_cities
filter to load your cities. This is done similarly to adding states/provinces.
It should be added on your functions.php or a custom plugin.
add_filter( 'wc_city_select_cities', 'my_cities' ); /** * Replace XX with the country code. Instead of YYY, ZZZ use actual state codes. */ function my_cities( $cities ) { $cities['XX'] = array( 'YYY' => array( 'City ', 'Another City' ), 'ZZZ' => array( 'City 3', 'City 4' ) ); return $cities; }
It’s also possible to use a list of cities without grouping them by state:
add_filter( 'wc_city_select_cities', 'my_cities' ); function my_cities( $cities ) { $cities['XX'] = array( 'City ', 'Another City' ); return $cities; }
Source code and contributions at github