Skip to content

Instantly share code, notes, and snippets.

@neltseng
Last active January 8, 2016 14:46
Show Gist options
  • Select an option

  • Save neltseng/388a022778ceed647350 to your computer and use it in GitHub Desktop.

Select an option

Save neltseng/388a022778ceed647350 to your computer and use it in GitHub Desktop.
WooCommerce Custom Checkout Field
// WooCommerce 台灣結帳表單 城市下拉選項
add_filter('woocommerce_states', 'cwp_woocommerce_tw_states');
function cwp_woocommerce_tw_states($states) {
$states['TW'] = array(
'基隆市' => '基隆市',
'台北市' => '台北市',
'新北市' => '新北市',
'宜蘭縣' => '宜蘭縣',
'桃園市' => '桃園市',
'新竹市' => '新竹市',
'新竹縣' => '新竹縣',
'苗栗縣' => '苗栗縣',
'台中市' => '台中市',
'彰化縣' => '彰化縣',
'南投縣' => '南投縣',
'雲林縣' => '雲林縣',
'嘉義市' => '嘉義市',
'嘉義縣' => '嘉義縣',
'台南市' => '台南市',
'高雄市' => '高雄市',
'屏東縣' => '屏東縣',
'花蓮縣' => '花蓮縣',
'台東縣' => '台東縣',
'澎湖' => '澎湖',
'金門' => '金門',
'馬祖' => '馬祖',
'離島地區' => '離島地區',
);
return $states;
}
add_filter('woocommerce_default_address_fields', 'cwp_custom_address_fields');
function cwp_custom_address_fields($fields) {
$fields2['first_name'] = $fields['first_name'];
$fields2['last_name'] = $fields['last_name'];
$fields2['state'] = $fields['state'];
$fields2['state']['class'] = array('form-row-first');
$fields2['city'] = $fields['city'];
$fields2['city']['class'] = array('form-row-last');
$fields2['postcode'] = $fields['postcode'];
$fields2['postcode']['class'] = array('form-row-first');
$fields2['address_1'] = $fields['address_1'];
$fields2['address_1']['class'] = array('form-row-last');
$fields2['email'] = $fields['email'];
$fields2['phone'] = $fields['phone'];
//$fields2['country'] = $fields['country'];
//$fields2['company'] = $fields['company'];
//$fields2['address_2'] = $fields['address_2'];
return $fields2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment