Woocommerce 是一个很是好的WordPress 电子商务插件,可是结帐页面用户地址不是很适合国内用户习惯,这里介绍怎么自定义结帐页面地址信息显示顺序。php
用户进入结帐(checkout)页面,用户地址信息显示效果以下:html
对于国内用户,姓确定在名以前,地址信息排列通常为:国家-》省-》市区-》详细地址ide
在你的主题的functions.php文件中添加以下代码:spa
1 // Change checkout page address 2 function custom_override_checkout_fields( $fields ) { 3 // billing address 4 $fields['billing']['billing_first_name']['class'] = array('form-row-last'); 5 $fields['billing']['billing_last_name']['class'] = array('form-row-first'); 6 $fields['billing']['billing_phone']['class'] = array('form-row-wide'); 7 8 $fields['billing']['billing_email']['class'] = array('form-row-wide'); 9 10 $fields['billing']['billing_state']['class'] = array('form-row-wide'); 11 12 13 14 15 // billing address order 16 $billing_order = array( 17 "billing_last_name", 18 "billing_first_name", 19 "billing_country", 20 "billing_state", 21 "billing_city", 22 "billing_address_1", 23 "billing_address_2", 24 "billing_phone", 25 "billing_email", 26 ); 27 28 29 foreach($billing_order as $field) 30 { 31 $billing_ordered_fields[$field] = $fields["billing"][$field]; 32 } 33 34 $fields["billing"] = $billing_ordered_fields; 35 36 return $fields; 37 } 38 39 add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
代码解释:插件
1 // 设置邮箱地址,在独占一行显示 2 3 $fields['billing']['billing_email']['class'] = array('form-row-wide'); 4 5 // 设置姓在前显示,名在后显示,可是两个在同一行 6 7 $fields['billing']['billing_first_name']['class'] = array('form-row-last'); 8 $fields['billing']['billing_last_name']['class'] = array('form-row-first'); 9 10 // 这个设置的是显示顺序,排在前面的,就在前面显示。 11 // 先显示姓,而后显示名,后面是国家、省份、城市、地址1、地址2、电话号码、邮箱 12 // 在这里不设置的字段,在前台不会显示出来 13 $billing_order = array( 14 "billing_last_name", 15 "billing_first_name", 16 "billing_country", 17 "billing_state", 18 "billing_city", 19 "billing_address_1", 20 "billing_address_2", 21 "billing_phone", 22 "billing_email", 23 );