Skip to content

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.

  1. 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.

  2. As a second step you also need to update your e-mail template to add the actual note from customer_notefield.
    This can be done by copying the following code to your template:

     {{depend order_data.customer_note}}
         <table class="message-info">
             <tr>
                 <td>
                     {{var order_data.customer_note|escape|nl2br}}
                 </td>
             </tr>
         </table>
     {{/depend}}
    
    Pay attention to 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.