I've created a woo-commerce checkout field with wooocmmerec checkout field editor plugin like the below image that is supposed to appear conditionally at the checkout and here is the code that enables it .
function ga_checkout_fields($fields) {
global $user_country;
//$user_country = 'in'; //for test in dev
if( $user_country != 'in') { //hide gst if the location is not india
unset($fields['billing']['billing_gst_number']);
}
if( $user_country != 'br') { //hide taxid if the location is not brazil
unset($fields['billing']['billing_br_tax_id']);
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'ga_checkout_fields' );
This code works flawlessly at the checkout but the problem is when a user tries to edit their billing address at my account then they see those custom fields and are not able to edit their address. I don't want to display nor save the custom fields at all to the customers at their my account edit billing address form.
I tried the below code to unset those custom fields at the billing address in my account, I am able to hide the fields but am not able to save them as the tax id field is required at the checkout. I want the tax id to be required at the checkout and I don't want to have any custom fields at the edit billing address in my account? Any insights on how to achieve that?
function ga_remove_the_address_field( $address, $load_address ) {//this removes fields in the edit form
global $user_country;
if( $user_country != 'in') { //hide gst if the location is not india
unset($address['billing_gst_number']);
}
if( $user_country != 'br') { //hide taxid if the location is not brazil
unset($address['billing_br_tax_id']);
}
return $address;
}
add_filter( 'woocommerce_address_to_edit', 'ga_remove_the_address_field', 10, 2 );
question from:
https://stackoverflow.com/questions/65621437/hide-custom-checkout-fields-from-appearing-in-woocommerce-my-account-edit-addres 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…