When a customer or user registers on the site, he can easily change and save his email in the Account details section, and that's it!
How can I prevent the change of the user's email in all parts and sections of the site and only the site administrator can change the user's email, not any other user or person, even the user himself?
I don't want to just hide this option by CSS or in the front end, but I want it to be completely removed or unusable so that the end user who has mastered CSS and... cannot change the email with tricks.
This is prohibited by most countries' legislation for internet websites, and more strongly on e-commerce business (EU countries are even stricter and have a hard position on the subject). Customer have the right to access/change/remove their data.
To remove the billing email address from My Account Edit Address and Checkout when the billing email already exists, use the following:
add_filter( 'woocommerce_billing_fields', 'disable_billing_email_changes' );
function disable_billing_email_changes( $billing_fields ) {
$billing_email = WC()->customer->get_billing_email();
// If email ealready xists
if ($billing_email) {
unset($billing_fields["billing_email"]); // Remove billing email field
}
return $billing_fields;
}
Code goes in functions.php file of the active child theme (or in a plugin). Tested and works.
To remove or hide the user email (when it already exists), from My Account Account details section, you will have to override via your child theme, the template file myaccount/form-edit-account.php
.
You will replace:
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" autocomplete="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
</p>
with the following:
<?php $current_user = wp_get_current_user();
if ( ! $current_user->user_email ) : ?>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" autocomplete="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
</p>
<?php endif; ?>