4

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!

  • Are you able to figure it out? – MagePsycho Nov 2 '17 at 7:04
3

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

  • Thank you. I have tried your way, but seem to not work. Does I need to changes anything else? I have changed in: vendor\Magento\Checkout\Block\Cart\LayoutProcessor. Please review my new attach image above. Thanks! – TriAnhHuynh Sep 28 '17 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.