WooCommerce styles the icon via this CSS file: woocommerce/assets/css/menu.css
, and here’s the corresponding code (pretty-printed or actually, I copied it from woocommerce/assets/css/menu.scss
):
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
font-family: 'WooCommerce' !important;
content: '\e03d';
}
So you can change the font-family
and the content
(and other) properties to suit your custom icon.
Below is an example of customizing the icon by changing it to use a background-image
:
// We hook to the `admin_enqueue_scripts` action with a priority of `11`, where
// at this point, the default CSS file should have been loaded. But you can or
// should add the CSS rule to your custom CSS file; just make sure it's loaded
// *after* the default CSS file.
add_action( 'admin_enqueue_scripts', function(){
$css = <<<EOT
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
content: ' ';
background: url('https://png.icons8.com/dusk/2x/e-commerce.png') no-repeat center;
background-size: contain;
}
EOT;
wp_add_inline_style( 'woocommerce_admin_menu_styles', $css );
}, 11 );
Note: The menu.css
file is registered and queued in WC_Admin_Assets::admin_styles()
with the handle/name of woocommerce_admin_menu_styles
.