简体   繁体   中英

Remove billing phone and email fields from my account edit address in WooCommerce

I'm trying to remove the phone number and email from the WooCommerce My Account edit address from but it's not working. I just want to show the address without the email and the phone number in the form. How can I do this?

What I tried:

<div class="woocommerce-address-fields__field-wrapper">
    <?php
    unset( $address[$fields['billing_phone']] );
    foreach ( $address as $key => $field ) {
        if ( isset( $field['country_field'], $address[ $field['country_field'] ] ) ) {
            $field['country'] = wc_get_post_data_by_key( $field['country_field'], $address[ $field['country_field'] ]['value'] );
        }
        woocommerce_form_field( $key, $field, wc_get_post_data_by_key( $key, $field['value'] ) );
    }
    ?>
</div>

This comes right out of the form-edit-address.php file. I've put it to my child theme because I've did some other changes. So it would be the best solution to remove the field in this PHP file.

Because of the email: I think that I must do something to prevent an error when I submit the form because this field is required there. But no clue how to do this.

The following code function will remove billing phone and email fields from My account > edit address:

add_filter( 'woocommerce_billing_fields', 'remove_account_billing_phone_and_email_fields', 20, 1 );
function remove_account_billing_phone_and_email_fields( $billing_fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        unset($billing_fields['billing_phone']);
        unset($billing_fields['billing_email']);
    }
    return $billing_fields;
}

Code goes in function.php file of the active child theme (or active theme). Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM