Created
September 8, 2020 07:36
-
-
Save gerharddt/bc733c31e5904805f9da081b3eb58b91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// change the checkout city field to a dropdown field | |
function nfh_change_city_to_dropdown( $fields ) { | |
$cities = array( | |
'', | |
'Nairobi', | |
'Nakuru', | |
'Eldorate', | |
'Mombasa', | |
'Kisumu', | |
'Diani', | |
'Malindi', | |
'Nyanyuki', | |
'Nyeri' | |
// etc | |
); | |
$city_args = wp_parse_args( array( | |
'type' => 'select', | |
'options' => array_combine( $cities, $cities ), | |
), $fields['shipping']['shipping_city'] ); | |
$fields['shipping']['shipping_city'] = $city_args; | |
$fields['shipping']['shipping_city']['class'][1] = 'select_city'; | |
$fields['billing']['billing_city'] = $city_args; | |
$fields['billing']['billing_city']['class'][1] = 'select_city'; | |
return $fields; | |
} | |
add_filter( 'woocommerce_checkout_fields', 'nfh_change_city_to_dropdown' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment