1

I want to add a dropdown for woocommerce cities.

I find a code for adding states as dropdown, but i dont know how to do this for cities. I try to make an analogy but it doesnt work.

Also, if posible i would like to shop cities based on the states, so i need a condition: if state = X then show this cities

The code for states was this:

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {
  $states['RO'] = array(
'TL' => 'Tulcea',
'VS' => 'Vaslui',
'VL' => 'Valcea',
'VN' => 'Vrancea'
  );

  return $states;
}

1 Answer 1

4

I havent found another way to do that except through this plugin https://github.com/8manos/wc-city-select , it adds functionality so you can do something like so

add_filter( 'wc_city_select_cities', 'my_cities' );

function my_cities( $cities ) {
  $cities['NG'] = array(
    'LA' => array(
        'Ikorodu',
        'Ikeja'
    ),
    'OY' => array(
        'Ibadan',
        'Saki'
    )
  );
  return $cities;
}

Of course the snippet will be in your functions.php

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