0

When I select a country WooCommerce checkout, how can I have state and city fields as dropdowns with the related data, like "when user select india then in state field shows only indian states". Please suggest what to do.

1

1 Answer 1

0

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.

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.