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

Ada*_*per 0 php account wordpress checkout woocommerce

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

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

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

Loi*_*tec 5

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

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

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;
}
Run Code Online (Sandbox Code Playgroud)

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

要删除或隐藏用户电子邮件(如果已经存在),请从“我的帐户”帐户详细信息部分中,您必须通过子主题(模板文件)进行覆盖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>
Run Code Online (Sandbox Code Playgroud)

具有以下内容:

<?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; ?>
Run Code Online (Sandbox Code Playgroud)

  • 所有“我的帐户”部分仅对登录的客户可见。使用 `if (! $current_user-&gt;user_email ) : ?&gt;` 只是从客户视图中删除电子邮件并将该字段保留在模板中的一种方法。由于该字段是在模板中硬编码的,因此没有其他方法可以通过您的子主题覆盖它。 (2认同)