Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 9:00 – 15:00 - -
- - - - - - -

Supporter timezone: Asia/Yerevan (GMT+04:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 5 months ago.

Assisted by: Christopher Amirian.

Author Posts
September 8, 2023 at 9:37 am #14365415

joostB-12

When i use get_term_link($term) i dont get the translated woocommerce product cat slug. In english it is product-category and in de its produkt-kategorie but i get product-category every time.

September 10, 2023 at 1:28 pm #14371321

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Please use the Hook below instead to get the correct Category:

https://wpml.org/wpml-hook/wpml_element_link/

Thanks.

September 11, 2023 at 1:35 pm #14376803

joostB-12

Hi,

When i add the following code it doesnt echo something:
echo apply_filters( 'wpml_element_link', $term->term_id, 'product_cat' );

September 13, 2023 at 6:35 am #14387127

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Ok this needs to be checked with our second-tier support.

I created a clean installation of WPML and Woocomemrce and imported some sample products and categories.

Please add a few translations there for a product and category and use the File Manager plugin there to add get_term_link($term) to show it is working ok on the original language but not working on the translated one.

Here is the dashboard access:

hidden link

I will report this as soon as you can replicate the issue there.

Thanks.

September 19, 2023 at 7:12 am #14416491

joostB-12

Hi,

Can show me how exactly I can use wpml_element_link when translating a product_cat slug that would be fine too.

September 20, 2023 at 8:53 am #14427771

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I tested an alternative solution in the clean installation and it worked:

function display_translated_product_category_link() {
    // Get the translated ID for the product category of ID 16
    $translated_id = apply_filters('wpml_object_id', 16, 'product_cat', true);

    // Get the term link for the translated ID
    $term_link = get_term_link($translated_id, 'product_cat');

    // If no error in fetching the link, display the link
    if (!is_wp_error($term_link)) {
        $term = get_term($translated_id, 'product_cat');
        echo '<a href="' . esc_url($term_link) . '">' . esc_html($term->name) . '</a>';
    } else {
        echo 'Error fetching translated product category link.';
    }
}

add_action('wp_footer', 'display_translated_product_category_link');

Use the "wpml_object_id" to get the ID of the translated category and then use it in your code.

For more information:

https://wpml.org/wpml-hook/wpml_object_id/

If you check the page footer you will see that it shows the translated product category link:

hidden link

Please consider that this method will show the translated category in its correct language, so if you check the same thing in the original language it will show the original category:

hidden link

Thanks.
[/php]

September 21, 2023 at 9:50 am #14437023

joostB-12

Hi,

i think it's something with the DE version of the website. Everything works on different languages but only on the DE version of the website it doesn't work.

September 24, 2023 at 11:19 am #14452293

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

As this is a code-related issue you can consider hiring a developer. We already mentioned the way to use the code to achieve what you need.

If you are interested you can check for a possible plugin conflict and check and see what is different in DE versions.

- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Switch to the default theme such as "TwentyTwenty" by going to "WordPress Dashboard > Appearance > themes".
- Go to "WordPress Dashboard > Plugins" and deactivate all plugins except WPML and its add-ons.
- Check if you can still recreate the issue.
- If not, re-activate your plugins one by one and check the issue each time to find out the plugin that causes the problem.

Thanks.

The topic ‘[Closed] When i use get_term_link($term) i dont get the translated woocommerce product ca’ is closed to new replies.