How to override order/order_comments.phtml template in Magento 2?

You can override order_comments.phtml file using layout XML by creating a module or directly add template file to the theme level under Magento_Sales module.

order_comments.phtml file used to show the order comment in order details view page.

order_comments.phtml file is declared under the sales_order_view.xml file in Sales Module.

  • Using Theme level,
app/design/frontend/<ThemePackage>/<themename>/Magento_Sales/templates/order/order_comments.phtml

You can see order comments by URL, <SITE_URL>/sales/order/view/order_id/1/

  • Using Module Level,

You need to create sales_order_view.xml file to add a template,

Path:
app/code/Rbj/History/view/frontend/layout/sales_order_view.xml

<?xml version="1.0"?>
<!--
/**
 * Order History layout
 *
 * @author  Rakesh Jesadiya
 * @package Rbj_History
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    	<referenceBlock name="order.comments" template="Rbj_History::order/order_comments.phtml" />
    </body>
</page>

Create order_comments.phtml file,
Path:
app/code/Rbj/History/view/frontend/templates/order/order_comments.phtml

Add Content from Sales Module order_comments.phtml file to your module custom template and modify the template.

Clear a cache and check your login page.