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?
New update:
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):-
The easiest would be to add a new entity where the values for your cities are stored. In the frontend, just change the input type to dropdown and load the list of cities. When a user selects a field from the dropdown, store the text value (as it is now). You could even do a check if the selected city is a valid one from your city list before storing the data.
This way you don't have to change a lot.
A more advanced approach (if needed) would be to also 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.
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):-
Hope this helps