10

I use magento 2.0.7 is it possible to custom the checkout page city field(text) to dropdown list?

1
  • oyenetwork.com/articles/… this explains how to add delivery date in checkout process, you can use same method to add city drop down. Hope that helps
    – Ekta Puri
    Aug 4, 2016 at 22:15

2 Answers 2

9
+50

Yes.

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.

1
  • Can you please share screen of the table as i am not finding any city field these tables Nov 20, 2019 at 12:02
3

for the sesion of estimate shipping and Tax of magento you will need overwrite of the class \Magento\Checkout\Block\Cart\LayoutProcessor.

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

enter image description here

2
  • 3
    can you provide tutorial code/github link for this
    – matinict
    Jul 5, 2018 at 8:02
  • Can you please provide a code here
    – Ask Xah
    Dec 1, 2018 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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