Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to change the Admin Menu name for "WooCommerce" to "Store Settings".

I tried the other code rename posts to articles, etc. but it did not work for WooCommerce.

WooCommerce's Admin Menu function is as below:

function woocommerce_admin_menu() {
    global $menu, $woocommerce;

    if ( current_user_can( 'manage_woocommerce' ) )
    $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' );

    $main_page = add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce' , 'woocommerce_settings_page', null, '55.5' );

    $reports_page = add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ),  __( 'Reports', 'woocommerce' ) , 'view_woocommerce_reports', 'woocommerce_reports', 'woocommerce_reports_page' );

    add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'woocommerce_attributes', 'woocommerce_attributes_page');

    add_action( 'load-' . $main_page, 'woocommerce_admin_help_tab' );
    add_action( 'load-' . $reports_page, 'woocommerce_admin_help_tab' );

    $wc_screen_id = strtolower( __( 'WooCommerce', 'woocommerce' ) );

    $print_css_on = apply_filters( 'woocommerce_screen_ids', array( 'toplevel_page_' . $wc_screen_id, $wc_screen_id . '_page_woocommerce_settings', $wc_screen_id . '_page_woocommerce_reports', 'toplevel_page_woocommerce', 'woocommerce_page_woocommerce_settings', 'woocommerce_page_woocommerce_reports', 'woocommerce_page_woocommerce_status', 'product_page_woocommerce_attributes', 'edit-tags.php', 'edit.php', 'index.php', 'post-new.php', 'post.php' ) );

    foreach ( $print_css_on as $page )
        add_action( 'admin_print_styles-'. $page, 'woocommerce_admin_css' );
}

add_action('admin_menu', 'woocommerce_admin_menu', 9);

Below code helps to change the Menu Name, but it causes the CSS files to not properly load on Settings page.

function change_woocommerce_menu_title( $translated )
{
    $translated = str_replace( 'WooCommerce', 'Store', $translated );
    $translated = str_replace( 'WooCommerce', 'Store', $translated );
    return $translated;
}
add_filter( 'gettext', 'change_woocommerce_menu_title' );
add_filter( 'ngettext', 'change_woocommerce_menu_title' );
share|improve this question
    
The above code I had earlier tried work, no solution needed. Thanks. –  Harish Chouhan May 26 '13 at 3:36
add comment

1 Answer 1

up vote 1 down vote accepted

This is what I do to rename menu items: in the action hook admin_menu, use a recursive array search to pinpoint the key position of the desired menu and then modify the global $menu array.

add_action( 'admin_menu', 'rename_woocoomerce_wpse_100758', 999 );

function rename_woocoomerce_wpse_100758() 
{
    global $menu;

    // Pinpoint menu item
    $woo = recursive_array_search_php_91365( 'WooCommerce', $menu );

    // Validate
    if( !$woo )
        return;

    $menu[$woo][0] = 'Store Settings';
}

// http://www.php.net/manual/en/function.array-search.php#91365
function recursive_array_search_php_91365( $needle, $haystack ) 
{
    foreach( $haystack as $key => $value ) 
    {
        $current_key = $key;
        if( 
            $needle === $value 
            OR ( 
                is_array( $value )
                && recursive_array_search_php_91365( $needle, $value ) !== false 
            )
        ) 
        {
            return $current_key;
        }
    }
    return false;
}
share|improve this answer
    
When using the above code I got an error Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in D:\wamp\www\euphoria\wp-includes\plugin.php on line 406 –  Harish Chouhan May 26 '13 at 6:43
    
Well, I tested before publishing and did again, no problems on my side. And cannot see a reason why there'd be a function missing any argument. Sorry to hear. –  brasofilo May 26 '13 at 7:17
    
Hi, This worked great when added in the functions.php. I was trying to add it in a custom plugin. Any suggestion how to make this work in the plugin? –  Harish Chouhan May 26 '13 at 11:07
    
I really don't know what could be going wrong on your side. Do you have debug enabled?. I tested as a Must Use plugin, a regular one and also inside functions.php. Works in all of them. –  brasofilo May 26 '13 at 13:39
    
Hi, Yes I hve debug enabled. But I guess it must be some error on my part as it worked well when placed in functions.php Thanks @brasofilo. Really appreciate your time. –  Harish Chouhan May 26 '13 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.