How To

How to Remove “Delete” Mass Action from Product Grid Programmatically in Magento 2?

Hello Magento Friends,

The current tutorial is about removing the “delete” mass action from the admin product grid in Magento 2. We will be performing the steps programmatically. Before starting let’s understand about delete action.

Magento 2 admin grid allows managing products and applying various bulk actions on them. One of the mass actions is “delete”. Look at the below image

Admin users can delete multiple products at a time. But if you want to remove the “Delete” option from the mass action for admin users, you can achieve it programmatically in Magento 2.

Steps to Remove “Delete” Mass Action from Product Grid Programmatically in Magento 2:

Step 1:  We need to create a “di.xml” file inside our extension at the following path

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

Then 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\Catalog\Ui\Component\Product\MassAction">
        <plugin name="hide_delete_from_catalog_massaction"
                type="Vendor\Extension\Plugin\Catalog\Ui\Component\Product\MassAction" sortOrder="1"/>
    </type>
</config>

Step 2:  After that, we need to create a “MassAction.php” file inside our extension at the following path

app\code\Vendor\Extension\Plugin\Catalog\Ui\Component\Product\

Then add the code mentioned below

<?php
namespace Vendor\Extension\Plugin\Catalog\Ui\Component\Product;

class MassAction
{
    public function afterIsActionAllowed(
        \Magento\Catalog\Ui\Component\Product\MassAction $subject,
        $isAllowed,
        $actionType)
    {
        if ($actionType == 'delete')
        {
            return false;
        }
        return $isAllowed;
    }
}

Result:

Check your Magento 2 product grid from the admin panel. You can see the “delete” option has been removed from the mass actions.

Conclusion:

This way you can successfully erase the “delete” action from the admin product grid in Magento 2. In case you are unable to achieve the desired result, get in touch with me through the comment box. I will be happy to help you.

You can also add a custom mass action to the product grid in Magento 2. Also, track all the activities performed by your admin users by installing Magento 2 Admin Action Log.

Share the article with your friends and stay updated with the latest articles.

Happy Coding!

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

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

19 hours ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

19 hours ago

Magento 2: How to Add Header and Footer in Checkout

Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…

2 days ago

Understanding Flexbox Layout in React Native

Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…

4 days ago

HYVÄ Themes Releases: 1.3.6 & 1.3.7 – What’s New

We're thrilled to announce the release of Hyvä Themes 1.3.6 and 1.3.7! These latest updates…

4 days ago

How Modern E-Commerce Platforms Leverage Docker & Kubernetes for Scalability

Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…

5 days ago