How To

How to Add Column in Orders Tab in Magento 2 Customer Admin Edit Page?

Hello Magento Friends,

Today I am going to illustrate How to Add Column in Orders Tab in Magento 2 Customer Admin Edit Page?

To efficiently fulfill orders, the admin needs to get additional information about the orders placed by the customers. To do this, Magento 2 store admin can add a custom column in the orders tab on the customer admin edit page.

Follow the below steps to Add Column in Orders Tab in Magento 2 Customer Admin Edit Page

Steps to Add Column in Orders Tab in Magento 2 Customer Admin Edit Page:

Step 1: Go to the below path

 app\code\Vendor\Extension\etc\adminhtml\di.xml

Now, add the below code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Block\Adminhtml\Edit\Tab\Orders"
                type="Vendor\Extension\Block\Adminhtml\Edit\Tab\Orders"/>
</config>

Step 2: Now, move to the below path

app\code\Vendor\Extension\Block\Adminhtml\Edit\Tab\Orders.php

And add the following code

<?php

namespace Vendor\Extension\Block\Adminhtml\Edit\Tab;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Helper\Data;
use Magento\Customer\Block\Adminhtml\Edit\Tab\Orders as BaseOrders;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory;
use Magento\Sales\Helper\Reorder;
use Magento\Sales\Model\Order\Config as OrderConfig;

class Orders extends BaseOrders
{
    /**
     * @var OrderConfig
     */    protected $orderConfig;

    /**
     * Orders constructor.
     *
     * @param Context $context
     * @param Data $backendHelper
     * @param CollectionFactory $collectionFactory
     * @param Reorder $salesReorder
     * @param Registry $coreRegistry
     * @param OrderConfig $orderConfig
     * @param array $data
     */    public function __construct(
        Context $context,
        Data $backendHelper,
        CollectionFactory $collectionFactory,
        Reorder $salesReorder,
        Registry $coreRegistry,
        OrderConfig $orderConfig,
        array $data = []
    ) {

        $this->orderConfig = $orderConfig;
        parent::__construct(
            $context,
            $backendHelper,
            $collectionFactory,
            $salesReorder,
            $coreRegistry,
            $data
        );
    }

    /**
     * @inheirtDoc
     */    public function setCollection($collection)
    {
        $collection->addFieldToSelect('status');
        parent::setCollection($collection);
    }

    /**
     * @inheirtDoc
     */    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumnAfter('status', array(
            'header' => __('Status'),
            'index' => 'status',
            'type'  => 'options',
            'width' => '70px',
            'options' => $this->orderConfig->getStatuses(),
        ), 'store_id');

        $this->sortColumnsByOrder();
        return $this;
    }
}

That’s it!

Conclusion:

Hence, this way you can Add Column in Orders Tab in Magento 2 Customer Admin Edit Page. Additionally, you can also Create a Custom tab in the Admin Customer Edit page in Magento 2.

In case of any difficulties, feel free to reach me via the comment box. Share the article and stay connected for more Magento 2 tutorials.

Happy Coding!

Click to rate this post!
[Total: 4 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

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

18 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

2 days ago

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

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

2 days ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

2 weeks ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago