Liquid, JavaScript, themes, sales channels
Hello,
I am trying to pull in some code from an order into an html file automatically. Sample below. Most of it is pulling in but I can't seem to get the Prodcut Title to pull in despite trying various combinations.
Anyone providing me insight?
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">${{ donation_amount }}0</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['name'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['created_at'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['created_at'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ shop['city'] }}</p>
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order['title'] }}</p>
It is specifically the last line about that isn't working for me. I have tried line_item.title. Removing the [ ] etc.
Solved! Go to the solution
This is an accepted solution.
Hi @Dan_GRHF,
the order has line_items. Each line_item might be connected to a product. So to go through all products in a order use
If you want to consider only the first product your line should read somehow like
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order.line_items[0].product.title }}</p>
see https://shopify.dev/docs/themes/liquid/reference/objects/order#order-line_items.
Regards
Thomas
This is an accepted solution.
Hi @Dan_GRHF,
the order has line_items. Each line_item might be connected to a product. So to go through all products in a order use
If you want to consider only the first product your line should read somehow like
<p style="font-family: Arial, Helvetica, sans-serif; margin: 0;">{{ order.line_items[0].product.title }}</p>
see https://shopify.dev/docs/themes/liquid/reference/objects/order#order-line_items.
Regards
Thomas
Thanks @tewe
I am totally not a developer and was just trying to get this to work for our site so your solution helped. I was able to pull it in with
{% for line_item in order.line_items %}
{{ line_item.title }}
{% endfor %}
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024