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,
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,
Share Improve this question asked Mar 31, 2017 at 5:13 Bry LedesmaBry Ledesma 251 gold badge1 silver badge4 bronze badges3 Answers
Reset to default 4You 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.
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!
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.