I need to create an observer of the vendor/magento/module-sales/Model/Order/Email/Sender/OrderCommentSender.php class, at the send() method (83th line), so that I can append a customized comment in the comments section.

Line 83 starts at $this->eventManager->dispatch

public function send(Order $order, $notify = true, $comment = '') {


$transport = [
    'order' => $order,
    'comment' => $comment,
    'billing' => $order->getBillingAddress(),
    'store' => $order->getStore(),
    'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
    'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
    'order_data' => [
        'customer_name' => $order->getCustomerName(),
        'frontend_status_label' => $order->getFrontendStatusLabel()

$transportObject = new DataObject($transport);

 * Event argument `transport` is @deprecated. Use `transportObject` instead.
    ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]


return $this->checkAndSend($order, $notify); }

2 Answers 2


How about you add comment to the $order and in the email, you get it from $order object?

No observer neeed

  • Actually I'm not aiming to simply add a comment to the email, but I need to get the comment's content from another table and then automatically add it to the comment section Mar 4, 2021 at 14:09

I suggest you try these steps:

Step 1: Choose the event that you would create an observer (access class OrderCommentSender search eventManager->dispatch, coppy event name)

Step 2: create events.xml file in folder (ex: //etc/events.xml)

Step 3: insert add observer code in XML file " instance="\\Observer\ClassNameObserver" />

Step 4: create new ClassNameObserver file following this path: //Observer/ClassNameObserver.php

Step 5: create function execute(Observer $observer) class ClassNameObserver implements \Magento\Framework\Event\ObserverInterface

     * @param Observer $observer
    public function execute(Observer $observer)
        //code implement at here
  • In the doubt that I had, I ended up managing to do it, I just forgot to give the feedback here. Thank you anyway! Mar 5, 2021 at 16:07
  • @myname2021 Can you post your solution? Dec 21, 2022 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.