How to make all fields optional in WooCommerce My account edit addresses only?
How to disable the required notice:
And the required html:
How to remove required? Can you help me?
2
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
you can understand in the picture
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). Tested and works.
Click here to cancel reply.
2
Answers
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
you can understand in the picture
To make all My account > addresses fields optional use the following:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.