Add dropdown list of cities in Woocommerce checkout page
我想在 Woocommerce 结帐页面的下拉列表中添加特定城市列表。
添加特定城市下拉列表的任何最佳解决方案。
我想在这个网站上添加下拉菜单 http://www.pkbrand.com
可以使用挂在
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Change"city" checkout billing and shipping fields to a dropdown add_filter( 'woocommerce_checkout_fields' , 'override_checkout_city_fields' ); function override_checkout_city_fields( $fields ) { // Define here in the array your desired cities (Here an example of cities) $option_cities = array( '' => __( 'Select your city' ), 'Karachi' => 'Karachi', 'Lahore' => 'Lahore', 'Faisalabad' => 'Faisalabad', 'Rawalpindi' => 'Rawalpindi', 'Gujranwala' => 'Gujranwala', 'Peshawar' => 'Peshawar', 'Multan' => 'Multan', 'Hyderabad' => 'Hyderabad', 'Islamabad' => 'Islamabad' ); $fields['billing']['billing_city']['type'] = 'select'; $fields['billing']['billing_city']['options'] = $option_cities; $fields['shipping']['shipping_city']['type'] = 'select'; $fields['shipping']['shipping_city']['options'] = $option_cities; return $fields; } |
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
经过测试并且可以工作。