If you setup a WooCommerce store on the Divi Theme, the header will display a count of the items in the user's cart. The text for this will be of the form "2 Items". 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_with_context', 'dbc_change_woocommerce_item_text', 20, 6);
function dbc_change_woocommerce_item_text($translation, $single, $plural, $number, $context, $domain ) {
if ($domain == 'Divi') {
if ($translation == '%1$s Item') { return '%1$s Article'; }
if ($translation == '%1$s Items') { return '%1$s Articles'; }
}
return $translation;
}
Related Post: Adding PHP to the Divi Theme
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). The %1$s in the above is a placeholder which will be replaced with the actual number of items when Divi outputs the page.
Thanks! But in which PHP file should I add this code?
Hi Victor, the best place is probably in the functions.php file of a child theme, but there are a few other options. See this post for more:
https://divibooster.com/adding-php-code-to-the-divi-theme/