将Woocommerce重命名为“订单"管理员子菜单 [英] Rename Woocommerce "Orders" admin submenu

查看:87
本文介绍了将Woocommerce重命名为“订单"管理员子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在WooCommerce中重命名订单子菜单?

How can I rename the order submenu in WooCommerce?

我已经尝试过这种方法,但是它不起作用:

I've tried it this way but it's not working:

add_filter( 'gettext', 'rename_texts', 20, 3 );
function rename_texts( $translated ) {      
    switch ( $translated ) {
        case 'Bestellungen' :
            $translated = __( 'My Tests', 'woocommerce' );
            break;
    }

    return $translated;
}

推荐答案

您需要使用gettext_with_context钩子代替gettext才能使其以这种方式工作:

You need to use gettext_with_context hook instead of gettext to be able to make it work this way:

add_filter('gettext_with_context', 'rename_woocommerce_admin_text', 100, 4 );
function rename_woocommerce_admin_text( $translated, $text, $context, $domain ) {
    if( $domain == 'woocommerce' && $context == 'Admin menu name' && $translated == 'Bestellungen' ) {
        // Here your custom text
        $translated = 'Custom text';
    }
    return $translated;
}

代码进入您的活动子主题(活动主题)的function.php文件中.经过测试,可以正常工作.

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

或者您也可以使用此方法来定位未翻译的订单"文本:

Or you can also use this that will target the non translated "Orders" text instead:

add_filter('gettext_with_context', 'rename_woocommerce_admin_text', 100, 4 );
function rename_woocommerce_admin_text( $translated, $text, $context, $domain ) {
    if( $domain == 'woocommerce' && $context == 'Admin menu name' && $text == 'Orders' ) {
        $translated = __('Custom text', $domain );
    }
    return $translated;
}

代码进入您的活动子主题(活动主题)的function.php文件中.经过测试,可以正常工作.

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

这篇关于将Woocommerce重命名为“订单"管理员子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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