Rumah > Soal Jawab > teks badan
Saya menggunakan woocommerce_checkout_fields
penapis untuk mengedit nilai label medan woocommerce. Ia berfungsi dengan baik pada halaman pembayaran (seperti yang anda jangkakan), tetapi saya tidak faham mengapa ia tidak berfungsi pada halaman akaun. Saya fikir bidang ini masih diambil dari tempat yang sama? Lebih khusus lagi, saya bercakap tentang medan alamat pada titik akhir edit alamat pada halaman akaun woocommerce?
Percubaan kod saya:
function custom_woocommerce_fields( $fields ) { // Billing Fields $fields['billing']['billing_first_name']['label'] = 'First name'; $fields['billing']['billing_last_name']['label'] = 'Last name'; $fields['billing']['billing_company']['label'] = 'Company name'; $fields['billing']['billing_address_1']['label'] = 'Street address'; $fields['billing']['billing_address_2']['label'] = 'Apartment, unit, etc.'; $fields['billing']['billing_city']['label'] = 'City'; $fields['billing']['billing_country']['label'] = 'Country'; $fields['billing']['billing_state']['label'] = 'County/State'; $fields['billing']['billing_postcode']['label'] = 'Postcode'; $fields['billing']['billing_email']['label'] = 'Email'; $fields['billing']['billing_phone']['label'] = 'Phone'; // Shipping Fields $fields['shipping']['shipping_first_name']['label'] = 'First name'; $fields['shipping']['shipping_last_name']['label'] = 'Last name'; $fields['shipping']['shipping_company']['label'] = 'Company name'; $fields['shipping']['shipping_address_1']['label'] = 'Street address'; $fields['shipping']['shipping_address_2']['label'] = 'Apartment, unit, etc.'; $fields['shipping']['shipping_city']['label'] = 'City'; $fields['shipping']['shipping_country']['label'] = 'Country'; $fields['shipping']['shipping_state']['label'] = 'County/State'; $fields['shipping']['shipping_postcode']['label'] = 'Postcode'; $fields['shipping']['shipping_email']['label'] = 'Email'; $fields['shipping']['shipping_phone']['label'] = 'Phone'; // Account Fields $fields['account']['account_username']['label'] = 'Username or email'; $fields['account']['account_password']['label'] = 'Password'; // Order Fields $fields['order']['order_comments']['label'] = 'Order notes'; return $fields; } add_filter( 'woocommerce_checkout_fields' , 'custom_woocommerce_fields' );
Medan dalam Akaun Saya >Alamat tidak disesuaikan (mengedit alamat pengebilan atau penghantaran).
P粉7148900532023-10-30 10:43:31
Perkara berikut akan mempengaruhi medan bahagian "Alamat" Akaun Saya dan medan pembayaran, membenarkan penyesuaian medan pengebilan dan penghantaran pada bahagian Akaun Saya yang berkaitan.
1) Untuk Akaun Saya dan medan alamat semasa pembayaran (Pengebilan dan Penghantaran) :
Dalam sesetengah kes, anda perlu menggunakan penapis ini pada medan alamat dan ia akan digunakan untuk semua Bidang lalai Pengebilan dan Penghantaran:
// Billing and Shipping fields on my account edit-addresses and checkout add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' ); function custom_override_default_address_fields( $fields ) { $fields['first_name']['label'] = 'First name'; $fields['last_name']['label'] = 'Last name'; $fields['company']['label'] = 'Company name'; $fields['address_1']['label'] = 'Street address'; $fields['address_2']['label'] = 'Apartment, unit, etc.'; $fields['city']['label'] = 'City'; $fields['country']['label'] = 'Country'; $fields['state']['label'] = 'County/State'; $fields['postcode']['label'] = 'Postcode'; return $fields; }
Anda boleh menggunakan teg bersyarat WooCommerce is_account_page() dan is_checkout() untuk menyasarkan halaman akaun saya atau halaman daftar keluar...
2) Untuk medan pengebilan pada akaun saya, edit alamat dan pembayaran:
// Billing fields on my account edit-addresses and checkout add_filter( 'woocommerce_billing_fields' , 'custom_billing_fields' ); function custom_billing_fields( $fields ) { // Billing Fields $fields['billing_first_name']['label'] = 'First name'; $fields['billing_last_name']['label'] = 'Last name'; $fields['billing_company']['label'] = 'Company name'; $fields['billing_address_1']['label'] = 'Street address'; $fields['billing_address_2']['label'] = 'Apartment, unit, etc.'; $fields['billing_city']['label'] = 'City'; $fields['billing_country']['label'] = 'Country'; $fields['billing_state']['label'] = 'County/State'; $fields['billing_postcode']['label'] = 'Postcode'; $fields['billing_email']['label'] = 'Email'; $fields['billing_phone']['label'] = 'Phone'; return $fields; }
3) Untuk medan penghantaran pada akaun saya, edit alamat dan pembayaran
// Shipping fields on my account edit-addresses and checkout add_filter( 'woocommerce_shipping_fields' , 'custom_shipping_fields' ); function custom_shipping_fields( $fields ) { // Shipping Fields $fields['shipping_first_name']['label'] = 'First name'; $fields['shipping_last_name']['label'] = 'Last name'; $fields['shipping_company']['label'] = 'Company name'; $fields['shipping_address_1']['label'] = 'Street address'; $fields['shipping_address_2']['label'] = 'Apartment, unit, etc.'; $fields['shipping_city']['label'] = 'City'; $fields['shipping_country']['label'] = 'Country'; $fields['shipping_state']['label'] = 'County/State'; $fields['shipping_postcode']['label'] = 'Postcode'; $fields['shipping_email']['label'] = 'Email'; $fields['shipping_phone']['label'] = 'Phone'; return $fields; }
4) Semua medan (lain) hanya digunakan semasa pembayaran:
// All fields only on checkout add_filter( 'woocommerce_checkout_fields' , 'other_custom_checkout_fields' ); function other_custom_checkout_fields( $fields ) { // Account Fields $fields['account']['account_username']['label'] = 'Username or email'; $fields['account']['account_password']['label'] = 'Password'; // Order Fields $fields['order']['order_comments']['label'] = 'Order notes'; return $fields; }
5) Selain itu, bergantung pada negara yang dipilih, anda sepatutnya perlu menggunakan penapis:
woocommerce_country_locale_field_selectors
woocommerce_get_country_locale_default
Ini dalam kelas WC_Country
.
Kod tersebut terdapat dalam fail functions.php bagi tema kanak-kanak aktif (atau tema aktif).
Dokumentasi rasmi berkaitan: Sesuaikan medan untuk pembayaran menggunakan tindakan dan penapis