I want to change the WooCommerce dashboard widget title from ‘WooCommerce Status’ to something else.
I understand that I need to use a hook in my functions.php but I’m struggling to make this work.
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!
EDIT:
This is a CSS only solution I subsequently created, should it be required for any reason.
*Note the PHP provided in the selected answer is best practice and should be used where possible (additionally, the markup/tags woocommerce uses are subject to change).
/* Change Dashboard 'WooCommerce Status' Title */ #woocommerce_dashboard_status h2 { font-size: 0; } #woocommerce_dashboard_status h2:before { content: "Sales Report"; font-size: 14px; }
Advertisement
Answer
Try the following instead:
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; }
Code goes in function.php file of your active child theme (or active theme). tested and works.