将 "WooCommerce" 仪表板菜单选项名称更改为 "Store"

Change the "WooCommerce" Dashboard Menu option name into "Store"

根据 7uc13r 的 回答,我正在尝试了解如何将 WooCommerce 更改为 Store.

我试过以下方法,但没有成功:

#1:调试,在仪表板上显示菜单数组

function debug_admin_menus() {
    global $menu, $submenu, $pagenow;
    if ( current_user_can('manage_options') ) {
        if( $pagenow == 'index.php' ) {  // print on dashboard
            echo '<pre>', print_r( $menu, 1 ), '</pre>'; // top level menus
            echo '<pre>', print_r( $submenu, 1 ), '</pre>'; // submenus
        }
    }
}
add_action( 'admin_notices', 'debug_admin_menus' );

#2:更改名称和子菜单名称(WooCommerce 不会更改,“所有产品”会更改)

function custom_change_admin_label() {
    global $menu, $submenu;
    $menu[70][0] = 'Store';
    $submenu['edit.php?post_type=product'][5][0] = 'All Plugins';
}
add_action( 'admin_menu', 'custom_change_admin_label' );

这足以将 WooCommerce 更改为 Store

function custom_change_admin_label() {
    global $menu, $submenu;
    
    // Change WooCommerce to Store
    $menu['55.5'][0] = 'Store';
}
add_action( 'admin_menu', 'custom_change_admin_label' );


结合您的 ,您将获得:

function custom_change_admin_label() {
    global $menu, $submenu;     
    
    // Change 'WooCommerce' to 'Store'
    $menu['55.5'][0] = 'Store';

    // Change 'All Products' to 'All Plugins'   
    $submenu['edit.php?post_type=product'][5][0] = 'All Plugins';
    
    // Contains the URI of the current page.
    $current_url = $_SERVER['REQUEST_URI'];
    
    // Make sure wc-admin / customers page will still work
    if ( strpos( $current_url, 'customers' ) == false) {
        // Remove 'Home' from WooCommerce menu
        remove_submenu_page( 'woocommerce', 'wc-admin' );
    }
} 
add_action( 'admin_menu', 'custom_change_admin_label', 99, 0 );