Advertisement

Facebook

How to Add Customer Comments to Order Emails in Hyvä Checkout

How to Add Customer Comments to Order Emails in Hyvä Checkout

If you are using Hyvä Checkout and want to include customer comments in the order emails, you might notice that it doesn’t do this by default. Instead of storing customer comments in the customer_note field of the order object, Hyvä Checkout saves them in the default order notes collection.

In this guide, we will walk you through the steps to:

  1. Save the customer comments into the customer_note field.
  2. Update your order email template to display these comments.

Let’s get started!

Step 1: Save Comments to the customer_note Field

By default, Hyvä Checkout doesn’t map the customer comment field to the customer_note field of the order. To fix this, you’ll need to add a new file in your custom module:

Create the fieldset.xml File

1. Go to your module’s /etc/ directory and create a new file named fieldset.xml.

2. Add the following code to this file:

<?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>

What This Does:

  • Maps the customer_comment field from the quote (checkout stage) to the customer_note field in the order (once the order is placed).
  • Ensures the customer comments are stored in the customer_note field of the order object.

Step 2: Update the Email Template

Now that the customer_note field contains the customer comment, you need to modify the order email template to display it.

Add the Following Code to Your Email Template

{{depend order_data.customer_note}}
    <table class="message-info">
        <tr>
            <td>
                {{var order_data.customer_note|escape|nl2br}}
            </td>
        </tr>
    </table>
{{/depend}}

Breaking Down the Code:

  1. {{depend order_data.customer_note}}: Checks if there is a customer comment. If no comment exists, this section will not be displayed.
  2. {{var order_data.customer_note|escape|nl2br}}:
    • escape: Protects the comment by removing any harmful or unintended HTML code.
    • nl2br: Converts any newlines in the comment into <br> tags, so they display properly in the email.

Step 3: Test Your Changes

  1. Place a Test Order: Use the Hyvä Checkout and leave a comment during the checkout process.
  2. Verify the Comment:
    • Check the Magento Admin Panel and confirm that the comment appears in the customer_note field.
    • Review the order confirmation email to ensure the comment is displayed correctly.
  3. Test for Edge Cases: Try leaving comments with special characters or multiple lines to ensure they display correctly.

Benefits of This Customization

  • Customer Satisfaction: Customers feel assured their instructions or requests are acknowledged.
  • Streamlined Operations: Your team can access customer notes directly in emails, reducing confusion.
  • Professional Email Communication: Adding customer notes makes your emails look more detailed and professional.

Conclusion

Adding customer comments to order emails in Hyvä Checkout is a simple yet impactful customization. By following the steps outlined above, you can map the comments to the customer_note field and display them in email templates. This not only improves communication but also enhances the customer experience.

If you have any questions or face challenges during the implementation, feel free to reach out. Let us know how this customization has improved your workflow!

Post a Comment

0 Comments

Buy Me A Coffee