0

I am looking for a feature to have zipcode, states and cities as dropdown and are chained. When states are selected first, cities are narrow down in a dropdown menu and zipcode can be populated automatically.

I found a very nice one: https://wordpress.org/plugins/states-cities-and-places-for-woocommerce/

But zipcode is not populated with selected cities. I tried to contact the plugin authors but there is no feedback.

Or is there any other way to approach this? Thank you so much!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Hsin
  • 61
  • 1
  • 8
  • Sorry this is really very complicate and absolutely too broad – LoicTheAztec Mar 21 '18 at 14:09
  • ok then if there is a way to chain zipcode and city in checkout page? That is, when I choose New York city, the zipcode will populate 1111 for example. – Hsin Mar 21 '18 at 23:36
  • Sorry this is really very long and complicate as you should need first to link groups of postcodes to towns + certainly a lot of code to extend WC classes – LoicTheAztec Mar 21 '18 at 23:39
  • ok. Thank you anyway. I just think anyway to extend the plugin. https://wordpress.org/plugins/states-cities-and-places-for-woocommerce/ – Hsin Mar 22 '18 at 01:17
  • oh yes why not… that could be very useful for that… – LoicTheAztec Mar 22 '18 at 02:19
  • that plugin only works for states and cities fields. And I am thinking of any possibility to extend it to zipcode. that would be complete and perfect solution. – Hsin Mar 22 '18 at 03:17

1 Answers1

0

I made a small change on the plugin adding an onchange on the city select on the javascript pluging file:

states-cities-and-places-for-woocommerce/js/place-select.js

On this line:

$citybox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="city_select" placeholder="' + placeholder + '" onchange="getZipCode()"></select>' );

Then I added this rudementary script on the cart page :

<script>
function getZipCode() {
 var city = document.getElementById("calc_shipping_city").value;
 if(city=="Nameofthecity1"){calc_shipping_postcode.value = "111111";}
 if(city=="Nameofthecity2"){calc_shipping_postcode.value = "222222";}
 ...
 document.getElementById('calc_shipping_postcode').readOnly = true;
}
</script>
Rodrick
  • 595
  • 10
  • 27