Change WooCommerce state and city checkout fields to dropdowns related to the chosen country

although it’s true that you can search on google, that’s probably why you’re here in the first place. The plugins mentioned are alternatives, but if you still wanna do it, here’s how to turn the city field into a dropdown:

/**
 * Change the checkout city field to a dropdown field.
 */
function jeroen_sormani_change_city_to_dropdown( $fields ) {

    $city_args = wp_parse_args( array(
        'type' => 'select',
        'options' => array(
            'city1' => 'name city 1',
            'city2' => 'name city 2',
            'city3' => 'name city 3',
        ),
    ), $fields['shipping']['shipping_city'] );

    $fields['shipping']['shipping_city'] = $city_args;
    $fields['billing']['billing_city'] = $city_args; // Also change for billing field

    return $fields;

}
add_filter( 'woocommerce_checkout_fields', 'jeroen_sormani_change_city_to_dropdown' );

ps: I use this code myself, but i claim no ownership over it as i did not write it.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)