Search code examples
phpwordpresswoocommercebackendgettext

Rename Woocommerce "Orders" admin submenu


How can I rename the order submenu in WooCommerce?

enter image description here

I've tried it this way but it's not working:

add_filter( 'gettext', 'rename_texts', 20, 3 );
function rename_texts( $translated ) {      
    switch ( $translated ) {
        case 'Bestellungen' :
            $translated = __( 'My Tests', 'woocommerce' );
            break;
    }

    return $translated;
}

Solution

  • You need to use gettext_with_context hook instead of gettext to be able to make it work this way:

    add_filter('gettext_with_context', 'rename_woocommerce_admin_text', 100, 4 );
    function rename_woocommerce_admin_text( $translated, $text, $context, $domain ) {
        if( $domain == 'woocommerce' && $context == 'Admin menu name' && $translated == 'Bestellungen' ) {
            // Here your custom text
            $translated = 'Custom text';
        }
        return $translated;
    }
    

    Code goes in function.php file of your active child theme (active theme). Tested and works.

    enter image description here


    Or you can also use this that will target the non translated "Orders" text instead:

    add_filter('gettext_with_context', 'rename_woocommerce_admin_text', 100, 4 );
    function rename_woocommerce_admin_text( $translated, $text, $context, $domain ) {
        if( $domain == 'woocommerce' && $context == 'Admin menu name' && $text == 'Orders' ) {
            $translated = __('Custom text', $domain );
        }
        return $translated;
    }
    

    Code goes in function.php file of your active child theme (active theme). Tested and works.