1

Is there a possibility to disable the email field on WooCommerce customer account details? Or Is there a hook or action available to do such thing? I'm just using a pre-made themes and not that much into PHP. Have tried this plugin called "Prevent Email Change" by Happy Plugins, but it didn't worked.

Would really appreciate any help from this.

Thanks,

2

You can do it by adding this code to functions.php:

function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_email']);    
    return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 1000, 1 );

But it is wrong approach, since WooCommerce uses email to notify user about status of the order.

| improve this answer | |
  • Hi, thanks for this. Yup I knew that. But what I wanted is that they can register their email upon checkout and then once their account has been completely created, they cannot change their email anymore on the Account Details page. Would that be possible? – Bry Ledesma Apr 3 '17 at 0:05
  • WordPress does not have filter or hook to prevent changing of email. Happy Plugin just disables email field on admin page, so it cannot prevent actions on Account Details page in WooCommerce. But what is reason to prohibit? Users are identified by ids. – KAGG Design Apr 3 '17 at 0:46
  • I have a valid reason for this. I am creating an eLearn site that has restricted access. Only users from whitelisted domains can join. The email validation is done upon registration, but users can still change their email via this page, which shoudn't happen. – pmdci Aug 18 '17 at 17:43
1

This is what I use. I was also troubleshooting with wrong emails on registered accounts. So I simply disabled the field and set it to 'required' => false if the user is logged in.

if ( is_user_logged_in() ) {
    $fields['billing']['billing_email'] = [
        'label' => 'E-Mail-Adresse',
        'required'  => false,
        'custom_attributes' => [
            'disabled' => 'disabled',
        ]
    ];
} else {
    $fields['billing']['billing_email'] = [
        'label' => 'E-Mail-Adresse',
        'required'  => true,

    ];
}

Hope this helps someone out there!

| improve this answer | |
-1

I found in this file: wp-content\plugins\woocommerce\includes\class-wc-countries.php:

public function get_address_fields( $country = '', $type = 'billing_' )

Set required to false and the email would be optional.

| improve this answer | |
  • 1
    Hi Manuel, welcome to wordpress.stackexchange. While your answer is technically correct i have to downvote it because editing a plugin like that isn't recommended. What would happen if the plugin we updated and the edits deleted? It's better to use a hook or filter function to accomplish OP's goal. Thanks for joining in, hopefully this is the first of many helpful answer you will provide :) – admcfajn Jul 13 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.