• I have added the code through Snippet, but the dropdown section from the checkout page doesn’t work. It seems doesn’t come with the city I add in the function.php file. Below is the code I have with WC select city, can you kindly let me know what the issue is:

    <?php
    add_filter( ‘wc_city_select_cities’, ‘my_cities’ );
    /**
    * Replace XX with the country code. Instead of YYY, ZZZ use actual state codes.
    */
    function my_cities( $cities ) {

    $cities[‘CL’] = array(
    ‘Metropolitana de Santiago’ => array(
    ‘Provincia de Chacabuco’,
    ‘Provincia de Cordillera’,
    ‘Provincia de Santiago’
    ),
    );
    return $cities;
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author mantish

    (@mantish)

    Hi,
    The problem I see here is that you’re not using a state code. You should use a 3-letter code instead of “Metropolitana de Santiago”.

    I can see that WooCommerce doesn’t include the states from Chile, so you probably need to add them like this:

    
    add_filter( 'woocommerce_states', 'my_states' );
    function my_states( $states ) {
    	$states['CL'] = array(
    		'XXX' => 'Name of state XXX',
    		'YYY' => 'Name of state YYY',
    		etc
    	)
    	return $states;
    }
    

    Another option would be to use the city names without a state. Like this:

    
    add_filter( 'wc_city_select_cities', 'my_cities' );
    function my_cities( $cities ) {
    	$cities['CL'] = array(
    		'Provincia de Chacabuco',
    		'Provincia de Cordillera',
    		'Provincia de Santiago'
    	);
    	return $cities;
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘The dropdown of town/city doesn’t work’ is closed to new replies.