<p>Not sure how you're outputting the url to the variant itself, but you can always create your own link and change the variant paramater to whatever you want.</p>
<p>Something link this: <code>{{product.url}}?keywordyouwanttouse={{variant.purchasableId}}</code></p>
<p>On your product page you can then check if the url has the parameter and get the data of that variant.</p>
<p>I use the following code at the top of my product template and then use the <code>selectedVariant</code>to display sku, images, prices, ...
Here I use the variant querystring but you can change that to whatever querystring paramater you want to use.</p>
<pre><code>{% set variantId = craft.app.request.getQueryParam('variant') ?? false %}
{%  if variantId %}
    {% set selectedVariant = craft.variants.id(variantId).one() %}
{% else %}
    {% set selectedVariant = product.defaultVariant %}
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-09-24T14:18:55.437Z
If you output `url` attribute of lineitem from cart, it links to specific variant, using keyword `variant`.
Piotr Pogorzelski
CC BY-SA 4.0
2020-09-22T12:02:50.550Z
2020-09-22T12:02:50.550Z
Steven Vandemoortele
<p>I noticed that variants can have their own URL when i outputted URL of line item in the cart. Url looks something like that:</p>
<pre><code>http://localhost/test/web/test-prod?variant=27
</code></pre>
<p>Is there any way to change <code>variant</code> keyword in URL to something else?</p>
<p>When we want to display specific variant on product page, we need to perform specific element query based on <code>variant</code> param ourselves, yes? Because only <code>product</code> variable is injected into template.</p>

<ecommerce>
Commerce - variant URL param
# Commerce - variant URL param

(Asked by: username_0 on 2020-09-21)

I noticed that variants can have their own URL when i outputted URL of line item in the cart. Url looks something like that:
http://localhost/test/web/test-prod?variant=27

Is there any way to change variant keyword in URL to something else?
When we want to display specific variant on product page, we need to perform specific element query based on variant param ourselves, yes? Because only product variable is injected into template.

**Tags:** ecommerce


---

## 1 answers

### Answer by username_1 on 2020-09-22. Score: 1

Not sure how you're outputting the url to the variant itself, but you can always create your own link and change the variant paramater to whatever you want.
Something link this: {{product.url}}?keywordyouwanttouse={{variant.purchasableId}}
On your product page you can then check if the url has the parameter and get the data of that variant.
I use the following code at the top of my product template and then use the selectedVariantto display sku, images, prices, ...
Here I use the variant querystring but you can change that to whatever querystring paramater you want to use.
{% set variantId = craft.app.request.getQueryParam('variant') ?? false %}
{%  if variantId %}
    {% set selectedVariant = craft.variants.id(variantId).one() %}
{% else %}
    {% set selectedVariant = product.defaultVariant %}
{% endif %}

> **Comments:**
> **username_0**: If you output `url` attribute of lineitem from cart, it links to specific variant, using keyword `variant`.  

---

