Adding customer comment to order e-mail template
By default, Hyvä Checkout does not store the customer comment to order object customer_note
field.
It uses the default order notes collection to store the comment.
-
To add the comment to the
customer_note
variable to order object you can create a file inside a module’s/etc/fieldset.xml
with the following content:<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd"> <scope id="global"> <fieldset id="sales_convert_quote"> <field name="customer_comment"> <aspect name="to_order" targetField="customer_note"/> </field> </fieldset> </scope> </config>
After that the
customer_note
field is filled whenever new order is placed with customer comment. -
As a second step you also need to update your e-mail template to add the actual note from
customer_note
field.
This can be done by copying the following code to your template:Pay attention to{{depend order_data.customer_note}} <table class="message-info"> <tr> <td> {{var order_data.customer_note|escape|nl2br}} </td> </tr> </table> {{/depend}}
escape|nl2br
part of the template as this will escape the comment sting from html and any other content and also will add line break to newlines.