searchable billing city as dropdown in wordpress
<?php
// Copy from here
/**
* Change the checkout city field to a dropdown field.
*/
function jeroen_sormani_change_city_to_dropdown( $fields ) {
$city_args = wp_parse_args( array(
'type' => 'select',
'options' => array(
'birmingham' => 'Birmingham',
'cambridge' => 'Cambridge',
'leicester' => 'Leicester',
'liverpool' => 'Liverpool',
'london' => 'London',
'manchester' => 'Manchester',
),
'input_class' => array(
'wc-enhanced-select',
)
), $fields['shipping']['shipping_city'] );
$fields['shipping']['shipping_city'] = $city_args;
$fields['billing']['billing_city'] = $city_args; // Also change for billing field
wc_enqueue_js( "
jQuery( ':input.wc-enhanced-select' ).filter( ':not(.enhanced)' ).each( function() {
var select2_args = { minimumResultsForSearch: 5 };
jQuery( this ).select2( select2_args ).addClass( 'enhanced' );
});" );
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'jeroen_sormani_change_city_to_dropdown' );