Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello,
I created a metaobject for reviews and in one of the fields I put a product variant.
When I loop the metaobject the review.product_variant property returns the gid of the variant.
<p>{{ review.product_variant }}</p>
// --> this returns the ID of each variant:
gid://shopify/ProductVariant/xxxxxxxxxxxxxx
I was able to extract the image of the variant with this code.
<img src="{{ review.product_variant | image_url: width: '400px' }}">
What I can't do is get the product url so that the user can click and take him to that product.
I'm looking for something like this:
<a href="{{ review.product_variant.url }}">Go to product</a>
Is there a filter that transform the gid to the product url? Or any other solution?
Metaobject screenshot
Any help is appreciated.
Thanks!
Here is the complete code.
<section class="reviews-section"> <div id="reviews-wrapper"> {% for review in shop.metaobjects.reviews.values %} <div id="reviews-card-num{{ forloop.index }}" class="reviews-card reviews-card-num{{ forloop.index }}"> <p class="reviews-description"> {{ review.description }} </p> <h4 class="reviews-customer-name">{{ review.customer_name }}</h4> <div class="reviews-image-wrapper"> <img src="{{ review.product_variant | image_url: width: '400px' }}" alt="" class="reviews-image"> </div> <p>{{ review.product_variant }}</p> </div> {% endfor %} </div> </section>
I had the same dilemma and finally found the answer!
Here are the product variant properties: https://shopify.dev/docs/api/admin-rest/2023-07/resources/product-variant
To get the product variant url:
<a href="http://yourdomain.co{{ review.product_variant.value.url }}">
yourdomain.co{{ review.product_variant.value.url }}
</a>
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024