I would like to add drop down list of cities to new order page in woocommerce, I know way to add this functionality to checkout page, but here I want to add this functionality to admin new order pages in Woocommerce.
Use the following hooked function for admin new order (where you will set your array of cities):
add_filter( 'woocommerce_admin_billing_fields' , 'admin_billing_city_select_field' );
function admin_billing_city_select_field( $fields ) {
global $pagenow;
// Only for new order creation
if( $pagenow != 'post-new.php' ) return $fields;
$fields['city'] = array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
'class' => 'js_field-city select short',
'type' => 'select',
'options' => array(
'' => __( 'Select a city…', 'woocommerce' ),
'Los Angeles' => __( 'Los Angeles', 'woocommerce' ),
'San Antonio' => __( 'San Antonio', 'woocommerce' ),
),
);
return $fields;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
If you want it to work also for admin edit order pages, you will remove the following line:
if( $pagenow != 'post-new.php' ) return $fields;