我使用Woocommerce並編輯了城鎮結算表單,其中包含需要用戶選擇的500個城鎮和城市的下拉菜單。我如何實現搜索框,以便他們能夠搜索他們的城鎮?將搜索框添加到下拉式Wordpress
我定製的那場在Woocommerce,使用下面的代碼
add_filter('woocommerce_default_address_fields' , 'customize_checkout_city_field');
function customize_checkout_city_field($address_fields) {
// Set HERE the cities (one line by city)
$towns_cities_arr = array(
'0' => __('Select your city', 'my_theme_slug'),
'paris' => 'Paris',
'versailles' => 'Versailles',
'cannes' => 'Cannes',
);
// Customizing 'billing_city' field
$address_fields['city']['type'] = 'select';
$address_fields['city']['class'] = array('form-row-last', 'my-custom-class'); // your class here
$address_fields['city']['label'] = __('Town/city', 'my_theme_slug');
$address_fields['city']['options'] = $towns_cities_arr;
// Returning Checkout customized fields
return $address_fields;
}
您有任何示例代碼供我們查看嗎? –
@CodeApprentice添加了生成該表單域的相關代碼 – Jonathan