How to add custom tab in admin Sales Order view magento 2?

In Magento 2, Sales Order Page in the admin panel, Many Tabs are available by native like Information, Invoices, Shipments, Credit Memos, Transactions and comment history.

For your custom requirement, you need to add extra tab in Order page, You can add your custom tab in Admin Order View page by just simple module.

You need to create simple module for add extra tab.

Refer below code snippet for add extra tab,
I have taken Rbj as Package name and OrderTab as Modulename for simplicity.
You need to create first registration.php and module.xml file for defining our module.

Path: app/code/Rbj/OrderTab/registration.php

Create module.xml file, Path: app/code/Rbj/OrderTab/etc/module.xml

We have added the dependency on Magento Sales Module to add the new tab. So we have defined the Magento_Sales module in sequence tag in the above XML file.

Now comes to the main entry point of a module,
For Add new tab, We must override the sales_order_view.xmlfile to add our logic of add custom tabs.

A Reference block sales_order_tabs contains the tab lists. so we need to create sales_order_view.xmlfile in our module at below path,

Path: app/code/Rbj/OrderTab/view/adminhtml/layout/sales_order_view.xml

In the above file, We have declared Block file for set your custom logic, you want to display in custom tabs.

Create a New Block PHP file, Path: app/code/Rbj/OrderTab/Block/Adminhtml/OrderEdit/Tab/View.php

Above file, We can declare a template file using a $_template variable.

protected $_template = 'tab/view/my_order_info.phtml' used for a template file for our custom tabs.

You can set Custom Tab label by getTabLabel() and set title by getTabTitle() function. You can define a custom function for your requirement in the above file.

You can get Current order data by calling Magento\Framework\Registry object.

Now we need to create a template file,
Path: app/code/Rbj/OrderTab/view/adminhtml/templates/tab/view/my_order_info.phtml

Now Run Upgrade command to install our module.

Now Go To Admin panel, login with your credentials,
Click on Left Sidebar, Sales -> Order Link,
Click on Any Order, You can get the last tab as your new custom tab in Order View page.

Check the Custom tab in Sales Order Page,


You can also add Extra button on Toolbar by, Add custom button on the sales order view admin page.