防止客户(用户)更改“我的帐户”页面或 WordPress 网站任何其他部分的“帐户详细信息”中的电子邮件

2024-01-07

当客户或用户在网站上注册时,他可以轻松更改并在“帐户详细信息”部分中保存他的电子邮件,仅此而已!

如何防止用户的电子邮件在网站的所有部分和部分被更改,并且只有网站管理员可以更改用户的电子邮件,而不能更改任何其他用户或个人,甚至用户本人?

我不想只是通过CSS或在前端隐藏此选项,但我希望它被完全删除或无法使用,以便掌握CSS的最终用户......无法使用技巧更改电子邮件。


大多数国家的互联网网站立法都禁止这样做,而电子商务业务的立法则更为严厉(欧盟国家对此更加严格并且立场强硬)。客户有权访问/更改/删除其数据。

当帐单电子邮件已存在时,要从“我的帐户编辑地址和结帐”中删除帐单电子邮件地址,请使用以下命令:

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;
}

代码位于活动子主题的functions.php 文件中(或插件中)。经过测试并有效。

要删除或隐藏用户电子邮件(如果已存在),请从“我的帐户”帐户详细信息部分中,您必须通过您的子主题覆盖 https://woocommerce.com/document/template-structure/, 模板文件myaccount/form-edit-account.php https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/templates/myaccount/form-edit-account.php.

您将替换:

    <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' ); ?>&nbsp;<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 $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' ); ?>&nbsp;<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; ?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

防止客户(用户)更改“我的帐户”页面或 WordPress 网站任何其他部分的“帐户详细信息”中的电子邮件 的相关文章

随机推荐