Skip to content

Instantly share code, notes, and snippets.

@varun-pluginhive
Last active December 28, 2018 15:07
Show Gist options
  • Save varun-pluginhive/77383993417e6db5a71292a9548b1542 to your computer and use it in GitHub Desktop.
Save varun-pluginhive/77383993417e6db5a71292a9548b1542 to your computer and use it in GitHub Desktop.
Snippet to convert city as Drop Down in WooCommerce Checkout. Note - Use only if you ship within that country
/**
* Snippet to convert city as Drop Down in WooCommerce Checkout
* Created at : 28 Dec 2018
* Updated at : 28 Dec 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/varun-pluginhive/77383993417e6db5a71292a9548b1542
*/
add_filter( 'woocommerce_checkout_fields', function( $fields ) {
$city_args = wp_parse_args( array(
'type' => 'select',
'options' => array(
null => "Select",
"Abu Dhabi" => "Abu Dhabi",
"Dubai" => "Dubai"
),
'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
return $fields;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment