Last active
July 23, 2020 05:53
-
-
Save elicohenator/e21d91af3ccffd60b16b2f63fc79df34 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 | |
/* | |
* Changing WooCommerce City field to dropdown with predifned cities. | |
* Based on https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ | |
*/ | |
function elicohenator_override_checkout_fields( $fields ) { | |
// Create args for city fields - same for shipping & billing | |
$city_args = wp_parse_args( array( | |
'type' => 'select', | |
'options' => array( | |
'tel-aviv-yaffo' => __('Tel Aviv Yaffo', 'domainname'), | |
'givatayim' => __('Givatayim', 'domainname'), | |
'ramat-gan' => __('Ramat Gan', 'domainname'), | |
'bat-yam' => __('Bat Yam', 'domainname'), | |
'holon' => __('Holon', 'domainname'), | |
'rishon-leziyon' => __('Rishon Leziyon', 'domainname'), | |
'herzliya' => __('Herzliya', 'domainname'), | |
'ramat-hasharon' => __('Ramat Hasharon', 'domainname'), | |
'hod-hasharon' => __('Hod Hasharon', 'domainname'), | |
'petah-tikwa' => __('Petah Tikwa', 'domainname'), | |
'raanana' => __('Raanana', 'domainname'), | |
'kfar-saba' => __('Kfar Saba', 'domainname'), | |
// Add as much as you wish... | |
), | |
), $fields['shipping']['shipping_city'] ); | |
// applying args to shipping & billing fields | |
$fields['shipping']['shipping_city'] = $city_args; | |
$fields['billing']['billing_city'] = $city_args; | |
// return with all form fields | |
return $fields; | |
} | |
add_filter( 'woocommerce_checkout_fields' , 'elicohenator_override_checkout_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment