How to add custom button in admin order detail page in magento 2

Suppose vendor name ‘SR‘ and Module name ‘RewriteSales

Create a plugin in SR/RewriteSales/etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Backend\Block\Widget\Context">
        <plugin name="add_custom_button_sales_veiw" type="SR\RewriteSales\Plugin\Widget\Context" sortOrder="1"/>

Then create in SR/RewriteSales/Plugin/Widget/Context.php

namespace SR\RewriteSales\Plugin\Widget;

class Context
    public function afterGetButtonList(
        \Magento\Backend\Block\Widget\Context $subject,
        if($subject->getRequest()->getFullActionName() == 'sales_order_view'){
                    'label' => __('Custom Button'),
                    'onclick' => "setLocation('window.location.href')",
                    'class' => 'ship'

        return $buttonList;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.