更改标签“用户名”到“帐号”在WooCommerce注册中 [英] Change label "username" to "account number" in WooCommerce registration

查看:174
本文介绍了更改标签“用户名”到“帐号”在WooCommerce注册中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将WooCommerce注册表单上的用户名标签更改为帐号标签。因此,当导出数据时,帐号将成为用户名。

I am trying to change "username" label on WooCommerce registration form to "account number" label. So when the data is exported, account numbers will become usernames.

我复制了以下代码并将其更改为:

I copied the following code and change it bit:

function woocommerce_reg_form() { 

add_filter( 'gettext', 'woocommerce_register_text' ); 
add_filter( 'ngettext', 'register_text' ); 
function register_text( $translating ) { 
    $translated = str_ireplace( 'Username or Email Address', 'Acc', $translating ); 
    return $translated; 
} 

add_action( 'woocommerce_registration_form' ); 

但这会给我带来错误,并且不起作用。我做错了什么?

But it is giving me errors and doesn't work. What I am doing wrong? Please guide me.

推荐答案

您的代码完全不正确。改为使用以下内容:

Your code is totally incorrect. Use the following instead:

add_filter( 'gettext', 'change_registration_usename_label', 10, 3 );
function change_registration_usename_label( $translated, $text, $domain ) {
    if( is_account_page() && ! is_wc_endpoint_url() ) {
        if( $text === 'Username' ) {
            $translated = __( 'Account number', $domain );
        } elseif( $text === 'Username or email address' ) {
            $translated = __( 'Account number or email address', $domain );
        }
    }

    return $translated;
}

代码进入活动子主题(或活动主题)的function.php文件)。经过测试并有效。

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于更改标签“用户名”到“帐号”在WooCommerce注册中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆