If you want to add a new button on the sales order view page in the admin side then you have to do that by the plugin.
Please follow the below steps.
Step 1: Create a di.xml file on the below path and paste the below code in it.
Path: app/code/Magemonkeys/CustomOrderButton/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoBackendBlockWidgetButtonToolbar">
<plugin name="add_custom_button_toolbar" type="MagemonkeysCustomOrderButtonPluginCustomButtonPlugin" />
</type>
</config>
Step 2: Create the plugin file on the below path and paste the below code in it.
Path: app/code/Magemonkeys/CustomOrderButton/Plugin/CustomButtonPlugin.php
<?php declare(strict_types=1);
namespace MagemonkeysCustomOrderButtonPlugin;
use MagentoSalesBlockAdminhtmlOrderCreate;
use MagentoFrameworkViewElementAbstractBlock;
use MagentoBackendBlockWidgetButtonButtonList;
use MagentoBackendBlockWidgetButtonToolbar as ToolbarContext;
class CustomButtonPlugin
{
public function beforePushButtons(ToolbarContext $toolbar,AbstractBlock $context,ButtonList $buttonList): array {
$orderObject = false;
$layoutName = $context->getNameInLayout();
if ('sales_order_edit' == $layoutName) {
$orderObject = $context->getOrder();
}
if ($orderObject) {
$url = 'My Custom URL'
$buttonList->add('custom_btn',['label' => __('Custom Button'),'on_click' => sprintf("location.href = '%s';", $url),'class' => 'primary custom_button','id' => 'custom_btn']);
}
return [$context, $buttonList];
}
}
?>

