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
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:
product.selected_variant
returns the variant object.To get the current variant id use
product.selected_variant.id