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