<p>Try using this code:</p>

<pre><code>{% set variantID = craft.request.getParam('variant') %}
{% set locales = craft.i18n.getSiteLocaleIds() %}

{% for locale in locales %}
    {% if variantID is defined %}
        {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale).first %}
        {% if localeEntry.locale == locale %}
            {{ localisedEntryUrl.getUrl() }}
        {% endif %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-05-09T18:45:07.200Z
Thank you for taking the time to respond! Unfortunately, this code produces the error: `Variable "localeEntry" does not exist.` If you meant entry.locale I tried it and it didn't work. Still produces the same link for all locales.
Panos Spiliotis
CC BY-SA 4.0
2018-05-03T08:56:14.963Z
2018-05-03T08:56:14.963Z
RvdB
<p>I have a website that uses Craft Commerce and I'm trying to add a language menu that points to the localised version of each product variant as follows:</p>

<pre><code>  {% set variantID = craft.request.getParam('variant') %}
  {% set locales = craft.i18n.getSiteLocales() %}

  {% for locale in locales %}
     {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale.id).first().url() %}
     {{ localisedEntryUrl }}
  {% endfor %}
</code></pre>

<p>The problem is that the code above always produces the variant url for one language. eg.</p>

<pre><code>/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356
</code></pre>

<p>whereas I would expect something like:</p>

<pre><code>/en/shop/ornaments/melisa?variant=9356
/de/shop/ornaments/melisa?variant=9356
/es/shop/ornaments/melisa?variant=9356
</code></pre>

<p>What am I doing wrong?</p>

<plugin-craftcommerce>
Is there a way to get the URL of the localised version of a product variant?
# Is there a way to get the URL of the localised version of a product variant?

(Asked by: username_0 on 2018-05-02)

I have a website that uses Craft Commerce and I'm trying to add a language menu that points to the localised version of each product variant as follows:
  {% set variantID = craft.request.getParam('variant') %}
  {% set locales = craft.i18n.getSiteLocales() %}

  {% for locale in locales %}
     {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale.id).first().url() %}
     {{ localisedEntryUrl }}
  {% endfor %}

The problem is that the code above always produces the variant url for one language. eg.
/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356
/en/shop/ornaments/melisa?variant=9356

whereas I would expect something like:
/en/shop/ornaments/melisa?variant=9356
/de/shop/ornaments/melisa?variant=9356
/es/shop/ornaments/melisa?variant=9356

What am I doing wrong?

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2018-05-03. Score: 1

Try using this code:
{% set variantID = craft.request.getParam('variant') %}
{% set locales = craft.i18n.getSiteLocaleIds() %}

{% for locale in locales %}
    {% if variantID is defined %}
        {% set localisedEntryUrl = craft.commerce.variants.id(variantID).locale(locale).first %}
        {% if localeEntry.locale == locale %}
            {{ localisedEntryUrl.getUrl() }}
        {% endif %}
    {% endif %}
{% endfor %}

> **Comments:**
> **username_0**: Thank you for taking the time to respond! Unfortunately, this code produces the error: `Variable "localeEntry" does not exist.` If you meant entry.locale I tried it and it didn't work. Still produces the same link for all locales.  

---

