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

查看:41
本文介绍了更改标签“用户名"到“帐号"在 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天全站免登陆