Ecommerce Shopify WordPress Discussion

Retrieving Other language Links using WPML Language Code and Post ID retrieved from Post URL

I am building a Custom Language Selector page that displays all the languages enabled in WPML in a separate Page for changing languages instead of the Language Selector widget. I am getting the previous page URL via $_SERVER['HTTP_REFERER'] I am getting Post/page ID using the below function. url_to_postid(); Then I have a foreach loop which returns the Language Code. I want to get the correct URL based on the Language code and Post ID. I tried using the below code for getting this done but its not working as expected. $previous_post_link = apply_filters( 'wpml_permalink', get_the_permalink( $last_visited_id ), $language_code ); This works partly. When I use this function, I get the URL of the Post ID based on the language code but the slug is not correct. "es" is the language code Below the URL is the URL of the Post ID that I send. https://www.domainname.com/kontakt/ The actual Spanish version of this URL and the expected result is below. https://www.domainname.com/es/contacto/ Instead, this displays the URL wrongly as https://www.domainname.com/es/kontakt/ Can someone help me understand the issue and help me solve this? Thanks in advance.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.