You’ll have to excuse me in advance, I’m an amateur coder and probably have this all wrong. The problem:
Along with any regular text input fields, in my store contact form I’m wanting the user to be able to submit any items that happen to be in the cart so that they are emailed to the store admin. I have also created custom properties for my products which are displayed in the cart correctly.
My reading tells me I need to define a hidden input field with in the form whose value calls the line item properties of the cart. Something like this?:
In the received email, all the text field data appears as expected (name, address etc) and the also ‘CartContents’ field but the data output is blank for this field. That is, no output of cart line items.
I have run a test using {{ page.title }} for the hidden input’s value attribute and this works nicely. I suspect the line properties object is not global and can’t be accessed from any file in the theme? I’m not sure how to access the cart object from the contact form.
Any thoughts on how I might achieve this? I can post the contact form code if it helps?
I have run a test using {{ page.title }} for the hidden input’s value attribute and this works nicely. I suspect the line properties object is not global and can’t be accessed from any file in the theme? I’m not sure how to access the cart object from the contact form.
As specified by Shopify, there is one line item for each distinct product variant in the cart. The line_item object can be accessed in all Liquid templates via cart.items, in notification email templates via line_items, on the order status page of the checkout, as well as in apps such as Order Printer.
cart.items
Returns all of the line items in the cart.
order.line_items
Returns an array of line items for the order.
checkout.line_items
Returns all the line items of the checkout.
Example:
{% for line_item in cart.items %}
{{ line_item.title }}
{% endfor %}
Many thanks for your advice. Using your example code below I’m now successfully receiving the product and variant title in the email. I’m wondering what would the code look like to output any product custom fields specified by the customer. I believe the custom fields are available via Line_item.properties…