BEFORE

AFTER

If you setup a WooCommerce store on the Extra Theme, then Extra’s header will display a count of the items in the user’s cart. The text for this will be of the form “2 Items”, with a corresponding “2 Items in Cart” tooltip. If you’d like to change this text, e.g. to translate it into another language, you can use the following PHP code:

add_filter('ngettext', 'change_woocommerce_item_text', 20, 5);
function change_woocommerce_item_text($translation, $single, $plural, $number, $domain ) {
    if ($domain == 'extra') {
		if ($translation == '%d Item') { return '%d Article'; }
		if ($translation == '%d Items') { return '%d Articles'; }
		if ($translation == '%d Item in Cart') { return '%d Article dans le Panier'; }
		if ($translation == '%d Items in Cart') { return '%d Articles dans le Panier'; }
    }
    return $translation;
}

As this is PHP code, it can be added to the theme by copying it into your theme or child theme's functions.php file. Please note that if you copy it into Extra's own functions.php file, it will be overwritten when the theme is updated. For that reason it's advisable to add it via a child theme. Please also be aware that mistakes made when altering the PHP code of a WordPress site can cause the site to become inaccessible. Please take a backup of your theme / child theme files prior to changing them so that you can restore the original version if necessary.

The code above example replaces the English text (both singular and plural forms) with the French equivalent (I hope – please correct me if I have mistranslated). It also translates the longer form of the text (i.e. %d Items in Cart) which appears in a tooltip if you hover over the cart. The %d in the above is a placeholder which will be replaced with the actual number of items when Extra outputs the page.