How can I get the variant Id of a product on Checkout.liquid?

gemedina
New Member
2 0 0

I'm using schema to customize the way user can set things on Shopify. So my code is like this:

{
    "type": "number",
    "id": "product_variant_id",
    "label": "Product ID"
}

If I run a console log on this i'm getting product handle:

product-handle-from-collection-x

It is possible to retrieve the first product variant ID of this product?

  • I tried to use {{ all_products["product-handle-from-collection-x"].first_available_variant.id }}
  • It works on Product Page. Not on Checkout

0 Likes
Mircea_Piturca
Shopify Partner
1462 39 285

Is your section installed on checkout? Be aware that checkout.liquid is a different template from theme.liquid.

A bit more info would help us to understand better the issue.

Finally—Add variant descriptions to your products
0 Likes
gemedina
New Member
2 0 0

Thanks for your attention Mircea,

Yes. The section is now rendering inside of the Checkout.liquid
Basically all I want is to allow the admin to pick a product via Shopify Customizer and then I get the product variant from it.

Right now when I `console.log` the `section.settings.gwp_product` I get the product Handle. 

I was wondering if I should do a json `/admin/api/2021-01` and filtering by Product Handle or if there is a simple way that I'm not seeing.

 

0 Likes