Home Forums WoodMart support forum DROPDOWN FOR WOOCOMMERCE CHECKOUT

DROPDOWN FOR WOOCOMMERCE CHECKOUT

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #146456

    topmosth
    Participant

    Hello, how can I modify the City/Town textbox on the checkout page of Woocommerce? Like making the City/Town as a Dropdown Box, and when they select one State, all the cities under that state will display as a dropdown element. Thank you!

    #146489

    Hello,

    You can try the below code in function.php file of your active child theme (or theme). As it works at my test site:

    // Change "city" checkout billing and shipping fields to a dropdown
    add_filter( 'woocommerce_checkout_fields' , 'override_checkout_city_fields' );
    
    function override_checkout_city_fields( $fields ) {
    // Define here in the array your desired cities (Here an example of cities)
        $option_cities = array(
             '' => __( 'Select your city' ),
            'Karachi' => 'Karachi',
            'Lahore' => 'Lahore',
            'Faisalabad' => 'Faisalabad',
            'Rawalpindi' => 'Rawalpindi',
            'Gujranwala' => 'Gujranwala',
            'Peshawar' => 'Peshawar',
            'Multan' => 'Multan',
            'Hyderabad' => 'Hyderabad',
            'Islamabad' => 'Islamabad'
        );
    
        $fields['billing']['billing_city']['type'] = 'select';
        $fields['billing']['billing_city']['options'] = $option_cities;
        $fields['shipping']['shipping_city']['type'] = 'select';
        $fields['shipping']['shipping_city']['options'] = $option_cities;
        return $fields;
    }

    Result: https://jmp.sh/CsWdx7F

    Best Regards.

    #146672

    topmosth
    Participant

    Hello, I have tried integrating that code last time. Yes, it is perfectly working. But the thing is, it doesn’t have some conditionals like if i select California as State/Country under the Town/City dropdown, it doesn’t display the Cities around California, instead it displays all the Cities in United States. It will be hard for the users to select their Cities with so much of options.

    #146724

    Hello,

    It is not possible to provide you a piece of code which works on those conditions that if the specific state/country is selected then the city/town around that specific state/country will shown in the drop down list.

    It requires customization to achieve that functionality and this is beyond our limitations and support policy.

    Best Regards.

    #146726

    topmosth
    Participant

    No worries. I already created a custom code for this condition. Thank you!

    #146728

    Hello,

    We are glad that you resolve the issue, You are the best :-).

    If you need any help in future, please feel free to contact us anytime, we are always here to help you.

    Thanks for contacting us,
    Have a great day :-)

    Topic Closed.
    Best Regards.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘DROPDOWN FOR WOOCOMMERCE CHECKOUT’ is closed to new replies.