更改管理仪表板WooCommerce窗口小部件标题 [英] Change admin dashboard WooCommerce widget title
问题描述
我想将WooCommerce仪表板小部件标题从"WooCommerce状态"更改为其他名称.
I want to change the WooCommerce dashboard widget title from 'WooCommerce Status' to something else.
我了解我需要在我的functions.php中使用钩子,但我正在努力使这项工作奏效.
I understand that I need to use a hook in my functions.php but I'm struggling to make this work.
我在WooCommerce中找到了生成仪表板小部件的功能和文件(plugins/woocommerce/includes/admin/class-wc-admin-dashboard.php)-并尝试使用add_action进行挂钩进入该功能,但无济于事,它什么都不做或抛出错误.
I've found the function and the file in WooCommerce that is generating the dashboard widget ( plugins/woocommerce/includes/admin/class-wc-admin-dashboard.php ) - and I've attempted to use add_action to hook into this function but to no avail unfortunately, it either does nothing or throws an error.
我能够创建一个全新的仪表板小部件,但这不是我所需要的.
I am able to create a completely new dashboard widget but that is not what I need.
I've referenced several answers and tutorials such as this one which comes close ( https://www.tychesoftwares.com/understand-wordpress-dashboard-widget-create-custom-dashboard-widget-woocommerce/ ).
我知道这应该很简单,但是我对钩子和过滤器的经验不足,无法实现这一目标-我们将不胜感激!
I know this should be very simple but I've not enough experience with hooks and filters to be able to pull this off - would appreciate any assistance!
推荐答案
请尝试以下操作:
add_filter( 'gettext', 'change_add_to_cart_message', 10, 3 );
function change_add_to_cart_message( $translated, $text, $domain ) {
global $pagenow;
if( $text === 'WooCommerce status' && $domain === 'woocommerce' && is_admin() && $pagenow === 'index.php' ){
$translated = __( 'WooCommerce summary', $domain );
}
return $translated;
}
代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试并可以正常工作.
Code goes in function.php file of your active child theme (or active theme). tested and works.
这篇关于更改管理仪表板WooCommerce窗口小部件标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!