Home > OS >  How to rename all action and titles of WooCommerce product post type
How to rename all action and titles of WooCommerce product post type

Time:04-14

Im using WooCommerce Plugin, and instead of the product I want to rename all titles and actions to Donations.

enter image description here

this is what i have tried :

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' );

// Change label
function custom_change_admin_label() {
    global $menu, $submenu;

    $menu[11][0] = 'Donation'; //instead Products
    $submenu['edit.php?post_type=product'][5][0] = 'All Donation'; // instead all products
}
add_action( 'admin_menu', 'custom_change_admin_label' );

I feel this is a very Clumsy and long way and maybe there is a better way or a plugin to rename/translate?

CodePudding user response:

add_filter('gettext', 'translate_text');
add_filter('gettext_woocommerce', 'translate_text');
add_filter('ngettext', 'translate_text');
add_filter('gettext_with_context', 'translate_text');

function translate_text($translated) {
    $translated = str_ireplace('Products', 'Donations', $translated);
    $translated = str_ireplace('Product', 'Donation', $translated);
    return $translated;
}

Add this to your active theme functions.php file

enter image description here

  • Related