skip to Main Content

When you have a page like domain.com/products/product_name?variant=variant_id

This means that the page that is being loaded is the variant of the specific product (product_name) here since there’s the url query “variant”.

Like for example, 1 tshirt has many variant colors, so the same design can have different variant pages (this is just a simple example)
I want to check if the current page is a variant of a product or not before it loads through liquid. How?

2

Answers


  1. You can use product.selected_variant that will return the variant ID if the get parameter is present or not.

    Based on that you will be able to write a simple if:

    {%- if product.selected_variant -%}
    
    {%- else -%}
    
    {%- endif -%}
    
    Login or Signup to reply.
  2. product.selected_variant returns the variant object.
    To get the current variant id use product.selected_variant.id

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search