PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

You need to log-in to create request (topic) to the support

Problems with translation

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
Hi there.
I have several problem with translation (WPML) of Filters made with Husky plugin.
The default language if French.
  1. The title of each filters is never translated.
    https://boutique.ramscores.com/en/shop/
    "Formations" should be translated"Bands".
  2. The values of each filters are translated, but the sort order should the same as the default language order.
    In French"Duos", then"Trios", then"Quarter", it is not alphabetical sort order , but I want to keep the same sort in English.
    The problem is the same both with drop down menu or checkboxes.

Thank you for any help.

Hello

Thank you for the detailed report. Two separate issues here, two separate solutions.

Issue 1 - filter title not translated.

Please go to WPML > String Translation and search for the title text"Formations". If it appears there, you can translate it directly without any code. If it does not appear, add this snippet to your functions.php:

add_filter('woof_filter_title', function ($title, $taxonomy_info, $index) {
    $lang = apply_filters('wpml_current_language', null);
    if ($lang === 'en' AND $title === 'Formations') {
        return 'Bands';
    } return $title;
}, 10, 3);

Issue 2 - sort order in English does not match French.

This happens because WPML creates separate term records for each language, and the translated terms get their own sort order which defaults to alphabetical. The French custom order is not automatically copied to English terms.

The fix is to set the same manual order for the English terms. If you are using a plugin like"Category Order and Taxonomy Terms Order" to manage the French order, switch WPML to English and set the same order there for the English terms. The plugin manages order per language separately.

If you are not using any ordering plugin, the order is likely being stored in term_order field. In that case please let us know and we will provide a code snippet to synchronize the order from French to English terms automatically.


Snippet: (not tested)

/**
 * Sync term_order from French (source language) to all WPML translations.
 * Covers both wp_terms.term_order field and"Category Order" plugin meta key 'order'.
 * One-time sync: visit wp-admin with ?sync_term_order=1 once, then remove the snippet.
 * Auto-sync: fires every time a French term is saved/updated.
 */

// One-time manual sync trigger: visit any wp-admin page with ?sync_term_order=1
add_action('admin_init', 'sync_wpml_term_order_from_source');
function sync_wpml_term_order_from_source() {

    if (!isset($_GET['sync_term_order']) || !current_user_can('manage_options')) {
        return;
    }

    $source_lang = 'fr';
    $taxonomies  = array('product_cat'); // add more taxonomies here if needed

    foreach ($taxonomies as $taxonomy) {

        $source_terms = get_terms(array(
            'taxonomy'   => $taxonomy,
            'hide_empty' => false,
            'lang'       => $source_lang,
        ));

        if (is_wp_error($source_terms) || empty($source_terms)) {
            continue;
        }

        global $wpdb;

        foreach ($source_terms as $source_term) {

            // Read order from wp_terms.term_order (used by most ordering plugins and WP itself)
            $term_order = (int) $wpdb->get_var($wpdb->prepare(
               "SELECT term_order FROM {$wpdb->terms} WHERE term_id = %d",
                $source_term->term_id
            ));

            // Also read from termmeta key 'order' (used by"Category Order and Taxonomy Terms Order" plugin)
            $meta_order = get_term_meta($source_term->term_id, 'order', true);

            // Get all language translations of this term via WPML
            $translations = apply_filters('wpml_get_element_translations', null, $source_term->term_taxonomy_id, 'tax_' . $taxonomy);

            if (empty($translations)) {
                continue;
            }

            foreach ($translations as $translation) {

                if ($translation->language_code === $source_lang || empty($translation->element_id)) {
                    continue;
                }

                // Get the actual term_id from term_taxonomy_id
                $translated_term_id = (int) $wpdb->get_var($wpdb->prepare(
                   "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d",
                    $translation->element_id
                ));

                if (!$translated_term_id) {
                    continue;
                }

                // Sync wp_terms.term_order
                $wpdb->update(
                    $wpdb->terms,
                    array('term_order' => $term_order),
                    array('term_id'    => $translated_term_id)
                );

                // Sync termmeta 'order' if it was set
                if ($meta_order !== '') {
                    update_term_meta($translated_term_id, 'order', $meta_order);
                }
            }
        }
    }

    wp_die('Term order sync complete. Remove the snippet or stop using ?sync_term_order=1.');
}

// Auto-sync whenever a French term is updated
add_action('edited_term', 'auto_sync_wpml_term_order_on_save', 10, 3);
function auto_sync_wpml_term_order_on_save($term_id, $tt_id, $taxonomy) {

    $source_lang   = 'fr';
    $current_lang  = apply_filters('wpml_current_language', null);

    if ($current_lang !== $source_lang) {
        return;
    }

    global $wpdb;

    $term_order = (int) $wpdb->get_var($wpdb->prepare(
       "SELECT term_order FROM {$wpdb->terms} WHERE term_id = %d",
        $term_id
    ));

    $meta_order = get_term_meta($term_id, 'order', true);

    $translations = apply_filters('wpml_get_element_translations', null, $tt_id, 'tax_' . $taxonomy);

    if (empty($translations)) {
        return;
    }

    foreach ($translations as $translation) {

        if ($translation->language_code === $source_lang || empty($translation->element_id)) {
            continue;
        }

        $translated_term_id = (int) $wpdb->get_var($wpdb->prepare(
           "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d",
            $translation->element_id
        ));

        if (!$translated_term_id) {
            continue;
        }

        $wpdb->update(
            $wpdb->terms,
            array('term_order' => $term_order),
            array('term_id'    => $translated_term_id)
        );

        if ($meta_order !== '') {
            update_term_meta($translated_term_id, 'order', $meta_order);
        }
    }
}

 

Add this snippet to your functions.php. Then visit any wp-admin page with ?sync_term_order=1 added to the URL, for example:

https://boutique.ramscores.com/wp-admin/?sync_term_order=1

This runs a one-time sync that copies the French term order to all translations. After the page says"sync complete", remove the snippet or simply stop using that URL — the auto-sync part at the bottom will keep things in sync automatically whenever you update a French term in the future. Please let us know if it works ...

Also read: https://products-filter.com/working-with-wpml

 

Hi Alex and thanks a lot for your help !

Issue 1 - filter title not translated.

I used your code snippet and adapted to my needs , it works great!

Issue 2 - sort order in English does not match French.

About that, finally I just went to Products / Attributes and Configure Terms.
Then in the header I changed the flag and then re-order the term with the sort I want to use ... and it seems to work.
So I didn't not try to code snippet.

Thanks a lot for your help!

Hello

You are Welcome! Feel free to open a new topic here if you have any further questions ...