[英]Make fields optional in WooCommerce My account edit addresses
To make all My account > addresses fields optional use the following:要使所有我的帐户 > 地址字段可选,请使用以下内容:
// Make all My account addresses fields optional
add_filter( 'woocommerce_default_address_fields' , 'filter_my_account_addresses_fields', 999 );
add_filter( 'woocommerce_billing_fields', 'filter_my_account_addresses_fields', 999 );
function filter_my_account_addresses_fields( $fields ) {
// Only on My account edit addresses
if ( is_wc_endpoint_url( 'edit-address' ) ) {
// Loop through existing fields
foreach( $fields as $field_key => $field_data ) {
// if they are required
if( $fields[$field_key]['required'] ) {
// Make them optional
$fields[$field_key]['required'] = false;
}
}
}
return $fields;
}
// Optionaly remove ("optional)" text from My account addresses fields
add_filter( 'woocommerce_form_field' , 'remove_account_addresses_optional_fields_label', 10, 4 );
function remove_account_addresses_optional_fields_label( $field, $key, $args, $value ) {
// Only on My account edit addresses
if ( is_wc_endpoint_url( 'edit-address' ) ) {
$optional = ' <span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>';
$field = str_replace( $optional, '', $field );
}
return $field;
}
Code goes in functions.php file of the active child theme (or active theme).代码位于活动子主题(或活动主题)的 functions.php 文件中。 Tested and works.
测试和工作。
works for option on checkout page "kurumsal"适用于结帐页面“kurumsal”上的选项
works for option on checkout page "bireysel"适用于结帐页面“bireysel”上的选项
my account > addresses - does not select and hide option and does not work我的帐户 > 地址 - 不选择和隐藏选项并且不起作用
my account > addresses - does not select and hide option and does not work我的帐户 > 地址 - 不选择和隐藏选项并且不起作用
you can understand in the picture你可以在图片中理解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.