Liquid: How to get product title in `abandoned_cart` email? - shopify

I want to inject some custom liquid in my abandoned cart email on Shopify. Shopify has docs here saying the product_title can be found under line_items under abandoned_cart.
I naturally assume you can get the product_title with something akin to...
<p>You left {{ abandoned_checkout.line_items[0].product_title }} in your cart.</p>
But this doesn't work. What's the proper way to get the product name of the first item?

If you are working with email template for "Abandoned checkout" in notification settings, this should work:
{{ subtotal_line_items[0].product.title }}
Loop code:
{% for line in subtotal_line_items %}
{{ line.product.title }}
{% endfor %}
And here is some useful documentation here:
https://help.shopify.com/en/manual/orders/notifications/email-variables#line-item

All products for the abandoned cart will keep here: subtotal_line_items and you should operate with the Product object. So in the your case it should be:
<p>You left {{ subtotal_line_items[0].product.title }} in your cart.</p>

Related

How To display title, image etc. from product meta field of type product?

I'm trying to display the products I saved in a meta field on my product detail page like this:
<h2>Cross Selling goes here</h2>
{{ product.metafields.custom.styled_with }}
... but all I get it is:
["GID://SHOPIFY/PRODUCT/7978216456473","GID://SHOPIFY/PRODUCT/7978217177369","GID://SHOPIFY/PRODUCT/7978217537817","GID://SHOPIFY/PRODUCT/7978217570585"]
How can I render these products? I want to access the product title, image etc.
I'm using the Dawn Theme.
Do I need to run a query or something?
Thanks in advance!
I tried this line of code
{{ product.metafields.custom.styled_with }}
and I expected that I would have access to the product information directly (product title etc.)
I solved this by adding .value
{% for recommended_product in product.metafields.custom.styled_with.value %}
{{ recommended_product.title }}
{% endfor %}

Get Shopify Product Meta Description

In the Collection Template, I would like to add the Meta Description instead of the normal Product Description. I tried to replace {{ product.description }} with {{ page_description | escape }} but nothing is showing up. Do I need to add something like {% for product in collection.products %} (doesn't work) around it?

Printing Product Variant HS Codes

I am trying to create an automated Commercial Invoice within Shopify, using the Liquid template language. I have everything working, except for the IMPORT/EXPORT Harmonized Codes (HS Tariff Codes) that are stored as variant meta-fields. Whenever I try to print them out using the following code, I get blanks:
{% for line_item in line_items %}
{{ line_item.variant.metafields.global_harmonized_system_code }}
{% endfor %}
Can someone help me pull these HS Codes for each product variant and print them on the Commercial Invoice using liquid to pull the meta-field?
Global is a namespace, try :
{{ line_item.variant.metafields.global.harmonized_system_code }}
The syntax is :
{{ your_object.metafields.namespace.key }}
Your Liquid is insufficient for the task at hand.
{{ line_item.variant.metafields.global_harmonized_system_code }}
That output is not valid. It might point to a set of one or more key value pairs, so you should really iterate on that. Example:
{% for mf in line_item.variant.metafields.global %}
{% if mf | first == 'harmonized_system_code' %}
<p> {{ mf | last }} how is that for some value! </p>
{% endif %}
{% endfor %}
Something like that is more precise and will go through the variant metafields allowning you to choose which ones to print out.
I am able to get the value using this
{{ line_item.variant.metafields.harmonized_system_code.value }}

Shopify - All Products

When I try to get all products, I get a list of "ProductDrop"
why is this happening?
{% for product in collections.all.products %}
products.push('{{ product }}')
{% endfor %}
ProductDrop is like a Product Object. Javasript is not aware that a productdrop is an object in liquid. You have to treat it as a string and specify the attribute of the product you would like.
{{ product.title }}
{{ product.id }}
If you are looking to grab the information for use later I would push the product.id and then use the ajax api to grab the product info as json.
https://help.shopify.com/themes/development/getting-started/using-ajax-api#get-product

Shopify link directly to other item

I have some items in my shopify store that have similar themed items that compliment it well.
I know I could just add an <a href link in there, but I'd like to do something that is actually part of liquid, and would also be easier for my non-programmer partner (who also has the authority to make me sleep on the couch :-( ...) to add these links. Is there a way to add a link using the liquid formatting? Something like This would go great with ${items.ellington-coffee-table-set}!?
It would be great to be able to access a product like this collections.my-collection-handle.products.my-product-handle, but unfortunately it is not possible to get a product by its handle in liquid.
You would have to loop through the collection to find the product like this:
{% for product in collections.my-collection-handle.products %}
{% if product.handle == 'my-product-handle' %}
{{ 'my product' | link_to: product.url }}
{% endif %}
{% endfor %}
But that looks pretty messy if all you want is a link to the product, and you still have to hard-code the product's handle. This would be simpler:
{{ 'my product' | link_to: '/products/my-product-handle' }}
Still not ideal, but probably a better alternative than coding an <a href=... link manually.