【问题标题】:Change texts "Billing" and "Shipping" in Woocommerce admin order pages [closed]在 Woocommerce 管理订单页面中更改文本“计费”和“运输”[关闭]
【发布时间】:2020-11-26 08:37:47
【问题描述】:

我正在尝试更改“Billing”(意大利语中的“Fatturazione”) 和“Shipping”(意大利语中的“Spedizion”e) 的标签文本Woocommerce 管理订单页面。

看下面的截图(相关文字为黄色)

例如,如果我想用“测试”更改帐单地址文本 和带有“测试 2”的送货地址文本,我该怎么做?

感谢任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce backend orders


    【解决方案1】:

    您可以按如下方式使用 WordPress gettext 挂钩(针对未翻译的原始文本)

    add_filter( 'gettext', 'change_admin_order_edit_pages_texts', 10, 3 );
    function change_admin_order_edit_pages_texts( $translated_text, $text, $domain ) {
        global $pagenow, $post_type;
    
        if( in_array($pagenow, ['post.php', 'post-new.php']) && 'shop_order' === $post_type && is_admin() ) {
            if( 'Billing' === $text ) {
                $translated_text = __('Test 1', $domain); // <== Here the replacement txt
            }
    
            if( 'Shipping' === $text ) {
                $translated_text = __('Test 2', $domain); // <== Here the replacement txt
            }
    
        }
        return $translated_text;
    }
    

    代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。

    【讨论】:

    • 谢谢@LoicTheAztec !!!它完美地工作。我很高兴你解决了我的问题。非常非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2019-05-30
    相关资源
    最近更新 更多