Magento Order Comments

Recently we had a request from a client to add a comment to orders (ie. the checkout process). If you have ever wanted to add a field where customers can enter comments to their order, follow on below to see how this can be added as an extension

First lets add the textarea field to the checkout review page.
We will copy the default file into our namespace and make changes there.
In your magento directory go to app/design/frontend/ and create the namespace directory and the others after it. I will use mcorner for our example mcorner/default/template/checkout/onepage/review. Make sure that you create the folder structure within the template namespace that your magento website is using at the moment.
Then copy the file info.phtml from the app/design/frontend/base/default/template/checkout/onepage/review directory into the newly created path.
Now we are ready to edit the info.phtml file in our namespace path. Here we have added the textarea to the form, lines 72-78.

 <div id="checkout-review-submit">
     <?php echo $this->getChildHtml('agreements') ?>
     <form action="" id="checkout-agreements" onsubmit="return false;">
       <div class="checkout-comments">
         <label for="orderComment"><?php echo $this->__('Order Comments (optional)'); ?></label>
         <textarea name="orderComment" id="orderComment" rows="3" cols="60"></textarea>
     <div class="buttons-set" id="review-buttons-container">

In your magento directory go to /app/code/local/ and create your namespace. I am using MCorner.
So create MCorner/OrderComments/etc and add the file config.xml with the following code:

 <?xml version="1.0"?>

Now we will setup the Observer.
In app/code/local/MCorner/OrderComments create the Model directory and within it the file Observer.php with the following code:

 class MCorner_Ordercomments_Model_Observer extends Varien_Object
     * Add a customer order comment when the order is placed
     * @param object $event
     * @return
     public function saveOrder($evt)
       $_order   = $evt->getOrder();
       $_request = Mage::app()->getRequest();

       $_comments = strip_tags($_request->getParam('orderComment'));

         $_comments = 'Additional Order Comments: ' . $_comments;

       return $this;

This will add a comment that will be displayed in the comments setion of the order in the Admin.

Last file we need to add is in app/etc/modules
Create file MCorner_All.xml with the following:

 <?xml version="1.0"?>

That’s it. Clear Magento’s cache and go test your new extension.
This extension works on version 1.6.0 –

14 thoughts on “Magento Order Comments

  1. I have been working on this type of module for EE 1.12 and my code is almost identical but the comment field isn’t showing up on the backend. If you could provide any assistance, that would be great.

    • Hi Emily,
      Not sure where you are having an issue. Confirm that you have added the textarea in the form. Then check that you have set the config.xml correctly to trigger your saveOrder method on checkout_type_onepage_save_order event.
      Setup your Method to save the comments and finally enable your extension in app/etc/modules xml file.
      And don’t forget CLEAR CACHE!

      Maybe you can give us more details.

      • I have doubled checked all of my files and everything is correct. The comments aren’t showing up on the back end or on the invoice. I’m not sure what’s wrong either as my code is copied and pasted from yours with the exception of the module name. Should the xml file in app/etc/modules/ be NameSpace_all.xml or NameSpace_Module.xml ? My text area is posted on the agreements.phtml in the form box and seems to be executing correctly but when testing orders, I do not see the comments the user makes shop up in the order details.
        Thanks for your help.

      • Emily,
        It does not matter whether you use the NameSpace_all.xml or NameSpace_Module.xml naming convention.
        This extension allows you to capture additional comments and record them in the Comments / Comments History of an order.
        If you need them to display on the order page, order email, invoice email or invoice page you will need to add additional code for that.
        Are you seeing the comments in the Admin for that order or in the orders Comments History? If so then it is working as expected.

  2. I am not seeing the comments appear in the Comment History on the backend. I am confused as to why this isn’t operating correctly. If you could help me, that would be awesome. Email me at emily*******@****.com,
    Thanks for everything.

  3. Hello Sarg, thanks for you code this work perfectly for me in my local machine but loading it to the server don’t works, i was loaded all files, any idea?

    Thanks in advance, regards!!

  4. Hi Luis,

    I am sorry your are having issues.

    There can be several reasons why the code is not working on production server.

    Make sure:

    1. Clean Magento cache then try it again.
    2. Make sure all files are uploaded including the one that goes into /app/etc/modules/
    3. make sure that the code does not conflict with any other extension you might have installed.

    Let us know how it goes.

  5. Thank you for this great tutorial! Works excellent on Magento, although I had to rename the folder “OrderComments” to “Ordercomments” with a lowercase “c” for it to work.

  6. Thank you for your tutorial i have been struggling with this for days. tried added magneto extension but none of them was working as i was using a custom theme. But this work with a little tinkering 🙂

    For anyone who is using a custom theme and this doesn’t work straight away. turn on your template hints in the back end. Go to your order review page and find where the info file is being sourced from and add

    div id=”checkout-review-submit”>
    getChildHtml(‘agreements’) ?>

    __(‘Order Comments (optional)’); ?>

    In that file. however remember if it is in the base file then copy over the whole folder to your own namespace.

Leave a Reply

Your email address will not be published. Required fields are marked *