How To

How to Add Split Button on Admin Sales Order View Page in Magento 2

Hello Magento Friends ?,

How are you guys doing? It’s a new week, a new day and hereby I am with a new subject, How to Add Split Button on Admin Sales Order View Page in Magento 2. Let’s not miss our formerly published blog, Magento 2: How to Display Categories in Alphabetical order Programmatically in Frontend.

Start Up

A split button is a UI component where the user can select the displayed option or any other option from the drop-down list. The displayed option is the one that is frequently used by most of the users. The drop-down list shows the options that are very rarely used. The admin sales order view page is where the store owner can see all the details of the orders placed by the customers. Sometimes, the Magento 2 store has a need to add a split button in the admin sales order view page. It is possible with the help of the below code. Here we go ?

Steps to Add Split Button on Admin Sales Order View Page in Magento 2

Step 1: Firstly, navigate to the following path

app\code\Vendor\Extension\etc\adminhtml\

Now, create a file named “di.xml” and add the following code

<?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="Magento\Sales\Block\Adminhtml\Order\View">
        <plugin name="addSplitButton" type="Vendor\Extension\Plugin\Block\Adminhtml\Order\View"/>
    </type>
</config>

Step 2: Now, navigate to the following path

app\code\Vendor\Extension\Plugin\Block\Adminhtm\Order

And create a file namedView.php”

Lastly, add the following code

<?php

namespace Vendor\Extension\Plugin\Block\Adminhtml\Order;
use Magento\Sales\Block\Adminhtml\Order\View as OrderView;

class View
{
    public function beforeSetLayout(OrderView $subject)
    {
        $addButtonProps = [
            'id' => 'test',
            'label' => __('Test'),
            'class' => 'add',
            'button_class' => '',
            'class_name' => 'Magento\Backend\Block\Widget\Button\SplitButton',
            'options' => $this->getCustomActionListOptions(),
        ];
        $subject->addButton('test',$addButtonProps);
    }
    protected function getCustomActionListOptions()
    {
        $splitButtonOptions=[
            'action_1'=>['label'=>__('Action 1'),'onclick'=>'setLocation("ACTION 1")'],
            'action_2'=>['label'=>__('Action 2'),'onclick'=>'setLocation("ACTION 2")'],
            'action_3'=>['label'=>__('Action 3'),'onclick'=>'setLocation("ACTION 3")']
        ];
        return $splitButtonOptions;
    }
}
?>

Sum Up

That’s it for today! You have successfully implemented How to Add Split Button on Admin Sales Order View Page in Magento 2 and you are free to customize this code according to your need for fetching data. Lastly, if you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends and let us know if you are facing any issue while implementing this code by commenting below.

Happy Coding ?

Click to rate this post!
[Total: 9 Average: 4.6]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

15 hours ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

1 day ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

3 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

6 days ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

6 days ago

Best Beginners Guide to Shopify Balance Account

If you are a Shopify admin, using a Shopify Balance Account for your business revenue…

6 days ago