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 named “View.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: 8 Average: 5]
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

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

1 day ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

4 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

7 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

7 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

1 week ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

1 week ago