1

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;
}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Mr. Jo
  • 4,946
  • 6
  • 41
  • 100

1 Answers1

2

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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Is it possible to rename all texts which hast "Orders" in it with your function? Should I change my question or ask a new one? – Mr. Jo Nov 16 '18 at 19:03
  • 1
    @Mr.Jo This answer code only work for "Orders" submenu item, so you should better ask a new question with all the necessary details. Just remember that you can't ask multiple questions in one or a question that involve too many different cases. – LoicTheAztec Nov 16 '18 at 19:23