[英]Customizing Woocommerce template my-account/form-edit-addresses
[英]Customizing my-account addresses fields in Woocommerce 3
我想刪除模板form-edit-addresses.php中的表單字段billing_adress_2。
要完成,可以像這樣對表單字段重新排序:
名-姓
電子郵件-電話
公司
地址1
郵編
市
州
此更改我只想將其應用於頁面(模板)form-edit-addresses.php
任何幫助表示贊賞
在“我的帳戶”>“地址”部分中,以下掛鈎的功能將:
您忘記了可以在$ sorted_fields數組中輕松重新排序的“國家”字段...
編碼:
// Account Edit Adresses: Remove and reorder addresses fields
add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields', 20, 1 );
function custom_default_address_fields( $fields ) {
// Only on account pages
if( ! is_account_page() ) return $fields;
## ---- 1. Remove 'address_2' field ---- ##
unset($fields['address_2']);
## ---- 2. Sort Address fields ---- ##
// Set the order (sorting fields) in the array below
$sorted_fields = array('first_name','last_name','company','address_1','country','postcode','city','state');
$new_fields = array();
$priority = 0;
// Reordering billing and shipping fields
foreach($sorted_fields as $key_field){
$priority += 10;
if( $key_field == 'company' )
$priority += 20; // keep space for email and phone fields
$new_fields[$key_field] = $fields[$key_field];
$new_fields[$key_field]['priority'] = $priority;
}
return $new_fields;
}
// Account Edit Adresses: Reorder billing email and phone fields
add_filter( 'woocommerce_billing_fields', 'custom_billing_fields', 20, 1 );
function custom_billing_fields( $fields ) {
// Only on account pages
if( ! is_account_page() ) return $fields;
## ---- 2. Sort billing email and phone fields ---- ##
$fields['billing_email']['priority'] = 30;
$fields['billing_email']['class'] = array('form-row-first');
$fields['billing_phone']['priority'] = 40;
$fields['billing_phone']['class'] = array('form-row-last');
return $fields;
}
// Account Displayed Addresses : Remove 'address_2'
add_filter( 'woocommerce_my_account_my_address_formatted_address' , 'my_account_address_formatted_addresses', 20, 3 );
function my_account_address_formatted_addresses( $address, $customer_id, $address_type ) {
unset($address['address_2']); // remove Address 2
return $address;
}
代碼進入您的活動子主題(或活動主題)的function.php文件中。 經過測試和工作。
如果您也想在結帳頁面上使其有效,則必須刪除以下行:
// Only on account pages if( ! is_account_page() ) return $fields;
在每個功能中(2次) ……
該代碼將更改您希望其在帳單郵寄地址中顯示的字段的順序。 將此代碼放在主題的functions.php文件中。
add_filter('woocommerce_address_to_edit', 'reorder_woocommerce_address_fields', 10, 2);
function reorder_woocommerce_address_fields( $address, $load_address) {
$new_address['billing_first_name'] = $address['billing_first_name'];
$new_address['billing_last_name'] = $address['billing_last_name'];
$new_address['billing_email'] = $address['billing_email'];
$new_address['billing_phone'] = $address['billing_phone'];
$new_address['billing_email'] = array(
'label' => __('Email', 'woocommerce'),
'required' => true,
'class' => array('form-row-first'),
);
$new_address['billing_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => true
);
$new_address['billing_company'] = $address['billing_company'];
$new_address['billing_address_1'] = $address['billing_address_1'];
$new_address['billing_postcode'] = $address['billing_postcode'];
$new_address['billing_city'] = $address['billing_city'];
$new_address['billing_state'] = $address['billing_state'];
return $new_address;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.