Accessing product data in checkout.liquid

Solved
Highlighted
New Member
2 1 2

Hello,

it seems that the global liquid variables  all_products and collections are not available in the checkout.liquid file. Is there any way to access liquid product object for a specified product? Code like the following, which is working in all other liquid files, is not working in checkout.liquid:

{{ all_products["product-handle"].title }}

I'm asking this because I want to display an upsell widget to customers that have only one product in their cart and ask them to add another (matching) one, so that they can get free shipping. But I don't want to hard-code product images, titles, prices etc. Any suggestions?

Best regards,

Moritz

1 Like
Highlighted
Shopify Partner
8 0 1

Hi Moritz,

I have the same problem, and the same request from a customer (upsell), we only have access to checkout and shop objects, but not products &collections. I'm interested in your solution.

Best regards,

Karim

0 Likes
Highlighted
New Member
2 1 2

This is an accepted solution.

Hello Karim,

the only workaround I found is to use the public Products Ajax API to fetch product data (inspired by this thread). You can find it's documentation here: https://shopify.dev/docs/themes/ajax-api/reference/product. Hope this works for you as well!

Best regards,

Moritz

1 Like
Highlighted
Shopify Partner
8 0 1

Thank you very much for this information, it should be easily be done !!!

Karim

0 Likes
Highlighted
Shopify Partner
8 0 1

Hello Mo19

I don't know if you've finished your project, for my part, I have one last problem.
With my upsell, the customer is obliged to create a new order, and therefore a new shipment, did you manage to get around this problem?

Thank you very much,

Karim

0 Likes
Highlighted
Shopify Staff
Shopify Staff
192 8 44

Marked the answer about the AJAX API as the solution to the original thread. 

As for your follow-up question, upselling through the API isn't explicitly supported. You'd need to create a new order, and therefore a new shipment, as you mentioned.

This is a feature that we know the developer community wants though, so make sure to subscribe to our changelog to keep up to date on any relevant developments.

1 Like
Highlighted
Shopify Partner
8 0 1

ok, I understand, I'm going to use a public application that allows it, I've seen this one : post purchase promotions  that should suit me while waiting for this possibility

Merci

0 Likes