I need to show order comment in file


I tried to use the code:

<?php $_history = $_order->getVisibleStatusHistory() ?>
<?php if (count($_history)): ?>
<div class="order-additional order-comments">
<dl class="order-about">
<?php foreach ($_history as $_historyItem): ?>
<span class='lowcase'><?php echo $_historyItem->getComment()?></span>
<?php endforeach; ?>
<?php endif?>

Did not work.

  • could you please add $_order object code ? – Pawan Oct 25 '19 at 3:51

First try with this code of Object Manager, if you get value converts it into Dependency Injection. Code are:

$orderId = $orderId;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
$order->addStatusHistoryComment('This comment is programatically added to last order in this Magento setup');

Hope this will help You !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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