使用以下钩子函数进行管理新订单(您将设置城市数组):
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;
}
代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。
如果您希望它也适用于管理编辑订单页面,您将删除以下行:
if( $pagenow != 'post-new.php' ) return $fields;