Magento 2 – How to Make Dropdown List for City Field in Checkout

magento2magento2.1.5

I want to custom field "City" to dropdown list in checkout page (magento 2.1.5).

Is it possible? How can do that?

enter image description here

New update:

enter image description here

Thank you!

Best Answer

By default there is no option in magento2 for making the city field as dropdown like state and country in the checkout page.

An approach would be to add relations to the directory_country and/or directory_country_region tables to only show cities which belong to the specific country or region selected in the checkout.

you will need to overwrite of the class \Magento\Checkout\Block\Checkout\LayoutProcessor by using 'options' value provided by the third party api for city(or use a custom array):-

 $elements = [
        'city' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('City'),
            'value' =>  '',
            'options' => array_option(),
        ],

Hope this helps

Related Topic