Support » Plugin: WooCommerce » Woocommerce checkout fields customization problem

  • Hello everyone!

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. Don’t use blockquote. ]

    WC Version: 2.0.12
    WP Version: WP 3.5.1
    PHP Version: 5.3.24

    My ultimate goal is to create a dropdown district option for some certain cities/states. Php and programming in general is not my league so i decided to utilize Woocommerce’s postcode field to turn them into district.

    For an easy follow, please log in to my site: with username: test, password:mayhem

    So i added a list of states for Vietnam by adding the below to function.php of my theme.

    add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
    function custom_woocommerce_states( $states ) {
      $states['VN'] = array(
        'VN1' => 'Hồ Chí Minh',
        'VN2' => 'Hà Nội',
        'VN3' => 'Cần Thơ',
        'VN4' => 'Đà Nẵng',
      return $states;

    At the same time override the address format and locale setting :

    add_filter( 'woocommerce_address_formats' , 'custom_override_address_formats' );
    function custom_override_address_formats( $address_formats ) {
    	$address_formats['VN'] = '{name}\n{company}\n{address_1}\n{city}\n{state}\n{postcode}\n{country}';
    	return $address_formats;
    add_filter( 'woocommerce_locale_settings' , 'custom_override_locale_settings' );
    function custom_override_locale_settings( $locale ) {
    	$locale['VN']['state']['required'] =  true;
    	$locale['VN']['postcode']['required'] =  true;
    	$locale['VN']['hidden']['hidden'] =  false;
    	return $locale;

    At first at this stage, the state options worked fine. I could pick a state and the shipping cost could automatically recalculate according to the setting. ( im using Table Rate Shipping plugin which can set a different shipping cost for each state)
    So i moved on to deal with the postcode/district thing. After awhile i realized i messed up the states options as you can see in the check out page. Now when i pick a state the auto shipping cost mechanism is not triggered.

    I also put this in form-checkout.php but it doesnt return anything.
    <?php _e( $woocommerce->customer->get_shipping_state() ); ?>

    Now i know that somehow WC can not get state value for shipping. However, the added states still appear everywhere else.

    Strangely enough, when i made the store available worldwide, the checkout page is like this:

    And when i made it only available to Vietnam, this happened:

    As you can see, the postcode field (which i renamed it into Quận) disappear when the store is worldwide. And when the store is Vietnam only, the state field gone blank!

    I have tried to reinstall, reactivate Woocommerce but nothing changed. Does anybody have a clue? The most frustrating thing is that the state field worked before and now it doesnt.

    Also if anybody has some idea how to trigger the postcode dropdown to show up when a state is selected please let me know. I want it to be the same way the country and state fields work. When you select a country, the state dropdown option show up accordingly. I know it has something to to with class-wc-countries.php and wocommerce.js and i tried to mess with them but things got out of hands.

    Im using the lastest WordPress and Woocommerce.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce checkout fields customization problem’ is closed to new replies.