I have added the city field as a dropdown list but I can't get it to show up in the backend. https://ibb.co/3rdsQpY
/* city dropdown */
// UPDATE CHECKOUT CITY FIELD
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
add_filter('woocommerce_admin_shipping_fields', 'custom_override_default_address_fields');// manual order
function custom_override_default_address_fields( $address_fields ) {
// Billing City
$address_fields['city']['type'] = 'select';
$address_fields['city']['label'] = __('City', 'custom-domain');
$address_fields['city']['priority'] = '41';
$address_fields['city']['class'] = array('my-field-class form-row-last');
$address_fields['city']['options'] = array(
// '' => __( 'Select unit type' ), /*= this will make empty field*/
'Jeddah' => __('Jeddah', 'custom-domain'),
);
// Sort
ksort($address_fields['city']['options']);
return $address_fields;
}
I tried to add the filter below but it didn't work. what am I missing?
add_filter( 'woocommerce_customer_meta_fields', 'custom_override_default_address_fields' );
The following will change billing and shipping city fields to a dropdown on
The code:
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Addition - Other billing and shipping fields
For other billing and shipping fields than WooCommerce default addresses fields you can replace:
by the 2 following hooked functions: