skip to Main Content

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.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


  1. To translate the sorting options, you can use one of the following code replacement instead:

    function translate_catalog_orderby_strings2( $orderby ) {
        if ( isset($orderby['menu_order']) ) {
            $orderby['menu_order'] = 'Výchozí řazení'; // 'Default sorting'
        }
        if ( isset($orderby['popularity']) ) {
            $orderby['popularity'] = 'Řadit dle oblíbené'; // 'Sort by popularity'
        }
        if ( isset($orderby['rating']) ) {
            $orderby['rating']     = 'Řadit dle průměrné hodnocení'; // 'Sort by average rating'
        }
        if ( isset($orderby['date']) ) {
            $orderby['date']       = 'Řadit dle nejnovější'; // 'Sort by latest'
        }
        if ( isset($orderby['price']) ) {
            $orderby['price']      = 'Řadit dle cena: nízká až vysoká'; // 'Sort by price: low to high'
        }
        if ( isset($orderby['price-desc']) ) {
            $orderby['price-desc'] = 'Řadit dle cena: vysoká až nízká'; // 'Sort by price: high to low'
        }
        return $orderby;
    }
    

    Or also:

    add_filter( 'gettext', 'translate_catalog_orderby_strings', 10, 3 );
    function translate_catalog_orderby_strings( $translated_text, $text, $domain ) {
        if ( is_admin() ) {
            return $translated_text;
        }
        if ( $text === 'Default sorting' ) {
            $translated_text = 'Výchozí řazení';
        } 
        elseif ( $text === 'Sort by popularity' ) {
            $translated_text = 'Řadit dle oblíbené';
        } 
        elseif ( $text === 'Sort by average rating' ) {
            $translated_text = 'Řadit dle průměrné hodnocení';
        } 
        elseif ( $text === 'Sort by latest' ) {
            $translated_text = 'Řadit dle nejnovější';
        } 
        elseif ( $text === 'Sort by price: low to high' ) {
            $translated_text = 'Řadit dle cena: nízká až vysoká';
        } 
        elseif ( $text === 'Sort by price: high to low' ) {
            $translated_text = 'Řadit dle cena: vysoká až nízká';
        } 
        return $translated_text;
    }
    

    Code goes on functions.php file of your child theme (or in a plugin). Tested and works.

    enter image description here

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search