问题描述
如何在WooCommerce中将所有字段设置为仅我的帐户编辑地址?
如何禁用所需通知:
和所需的html:
如何删除必需的?你能帮我吗?
解决方法
要使所有“我的帐户”>“地址”字段为可选字段,请使用以下命令:
// Make all My account addresses fields optional
add_filter( 'woocommerce_default_address_fields','filter_my_account_addresses_fields',999 );
add_filter( 'woocommerce_billing_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;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
,works for option on checkout page "kurumsal"
works for option on checkout page "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
您可以在图片中了解