I am trying to translate Woocommerce product sorting to the language of my country from the original english version.
Unfortunately it is working only partly, the text "Sort by" just can not be translated.
What I consider as a best option, I decided to edit the text using functions.php
file in my Avada theme.
As I mentioned, there is only a part of a working code even if I use the same method (you can find it below).
function woosuite_change_cart_totals_text( $translated_text, $text, $domain ) {
if ( $text === 'Default Order' ) {
$translated_text = 'Výchozí';
}
if ( $text === 'Name' ) {
$translated_text = 'Jméno';
}
if ( $text === 'Popularity' ) {
$translated_text = 'Oblíbené';
}
if ( $text === 'Sort by ' ) {
$translated_text = 'Řadit dle ';
}
return $translated_text;
}
add_filter( 'gettext', 'woosuite_change_cart_totals_text', 20, 3 );
What is translated after this is visible in this screenshot. The text "Sort by " contains a space but I was trying to change without and still not working. It will translate everything without text "Sort by ".
Another attempt what I tried is also below (also not working):
add_filter('woocommerce_catalog_orderby', 'wc_customize_product_sorting');
function wc_customize_product_sorting($sorting_options){
$sorting_options = array(
'menu_order' => __( 'Řazení', 'woocommerce' ),
'popularity' => __( 'Oblíbenost', 'woocommerce' ),
'price' => __( 'Cena: od nejnižší', 'woocommerce' ),
'price-desc' => __( 'Cena: od nejvyšší', 'woocommerce' ),
);
return $sorting_options;
}
The same case is with the numbered of shown products (pagination).
Thank you for any help!
2
Answers
To translate the sorting options, you can use one of the following code replacement instead:
Or also:
Code goes on functions.php file of your child theme (or in a plugin). Tested and works.
I’m using the Avada theme with its required plugins. However, the Loco Translate plugin (https://wordpress.org/plugins/loco-translate/) didn’t cover product sorting options. I had to change a file named fusion-woo-sorting.php located in the wp-content/plugins/fusion-builder/shortcodes folder.
Photo In editor
Photo After translation
Note: there are two files with the same name fusion-woo-sorting.php.
The second one is in the …/fusion-builder/front-end/… folder, but I didn’t need to change it.