简体   繁体   中英

Remove items count from my account orders table in Woocommerce

I need to remove this item count text in my orders table at the my account page, because I don't need it:

在此处输入图像描述

The text at Gesamtsumme should be changed from:

234,35€ for 1 Artikel

to

234,35€

I've tried it with deleting it in the file but I want to do this via my functions.php because this is better I think.

The correct way to make it work for singular and plural item count, for all languages is (where $text is the untranslated string) :

add_filter('ngettext', 'remove_item_count_from_my_account_orders', 105, 3 );
function remove_item_count_from_my_account_orders( $translated, $text, $domain ) {
    switch ( $text ) {
        case '%1$s for %2$s item' :
            $translated = '%1$s';
            break;

        case '%1$s for %2$s items' :
            $translated = '%1$s';
            break;
    }
    return $translated;
}

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

Please add the following code under functions.php file

function replace_content($content)
{
$content = str_replace('für 1 Artikel', '',$content);
return $content;
}
add_filter('the_content','replace_content');

This finaly made it:

add_filter('ngettext', 'rename_place_order_button' );
function rename_place_order_button( $translated, $text, $domain ) {
    switch ( $translated ) {
        case '%1$s für %2$s Artikel' :
            $translated = __( '%1$s', 'woocommerce' );
            break;
    }
    return $translated;
}

For future reference, if you are using a translation plugin like Loco Translate, you can also change the translation there so no code is necessary.

Search for the following 2 strings:

%1$s for %2$s item

%1$s for %2$s items

Change both to:

%1$s

This will only display the total price of the order in the orders list of the 'my account' page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM