I have managed to add custom checkout city dropdown field by following method
$fields['shipping']['shipping_city'] = array(
'label' => __('City', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => true,
'clear' => true,
'type' => 'select',
'class' => array('own-css-name'),
'options' => array(
'New_York_City' => __('New York City', 'woocommerce' ),
'Chicago' => __('Chicago', 'woocommerce' ),
'Dallas' => __('Dallas', 'woocommerce' )
)
);
I want to get the option values from city taxonomy so I have tried the following method but it doesn’t seems to work (http://i.stack.imgur.com/dasIm.jpg)
$args = array(
'child_of' => 0,
'type' => 'product',
'taxonomy' => 'city',
'hide_empty' => 0
);
$categories = get_categories( $args );
foreach ($categories as $category) {
$cityArray[] = "'".$category->slug."' => __('".$category->name."', 'woocommerce' )";
}
$fields['shipping']['shipping_city2'] = array(
'label' => __('City', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => true,
'clear' => true,
'type' => 'select',
'class' => array('own-css-name'),
'options' => array(implode( ', ', $cityArray ) )
);
Try this .
Just replace the
For Loop with
foreach ($categories as $category) {
$cityArray[$category->slug] = $category->name;
}
Set option like this
‘options’ => array_values($cityArray)
Have tested the same and the results where as follows
Let me know if this worked for you.