You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce中修改结账页面用户名标签为Correo的PHP代码失效问题

修改WooCommerce结账页面“Username or Email Address”文本为“Correo”

你的代码无效是因为两个关键错误:

  • 函数名与过滤器名重复,引发冲突
  • 错误使用自定义键名修改字段,正确的字段标签键是label

正确代码方案

方案一:同时修改结账账户字段和登录区域标签

// 修改结账页面账户字段及登录区域的用户名/邮箱标签为"Correo"
add_filter( 'woocommerce_checkout_fields', 'custom_checkout_account_label' );
function custom_checkout_account_label( $fields ) {
    if ( isset( $fields['account']['account_username'] ) ) {
        $fields['account']['account_username']['label'] = __( 'Correo', 'woocommerce' );
    }
    // 同步修改登录表单的标签
    add_filter( 'woocommerce_login_form_username', 'custom_login_username_label' );
    return $fields;
}

function custom_login_username_label( $label ) {
    return __( 'Correo', 'woocommerce' );
}

方案二:直接修改所有登录场景的标签

如果只需要修改登录相关的标签(包含结账页面的登录区域),可以用更简洁的代码:

// 修改WooCommerce所有登录表单(含结账页面)的用户名/邮箱标签为"Correo"
add_filter( 'woocommerce_login_form_username', 'custom_woocommerce_login_label' );
function custom_woocommerce_login_label( $label ) {
    return __( 'Correo', 'woocommerce' );
}

使用说明

将代码添加到当前主题的functions.php文件末尾,或者使用自定义代码插件(如Code Snippets)添加,避免主题更新导致代码丢失。

内容的提问来源于stack exchange,提问作者luis Lagos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 13:18:13