1

I want to hide order from sales order grid with status like 'pending_payment'. How can I do in Magento 2?

1 Answer 1

1

I have tried to hide orders which have status 'canceled'. I have used plugin method for it.

In your custom module please create files as per mentioned below

Step 1 : Please create di.xml file under PackageName/Hideorders/etc/adminhtml/

<?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\Framework\View\Element\UiComponent\DataProvider\Reporting">
        <plugin name="sales_grid_collection" type="PackageName\Hideorders\Model\Plugin\Sales\Order\Grid"/>
    </type>
</config>

Step 2: Please create file Grid.php file under PackageName/Hideorders/Model/Plugin/Sales/Order/

<?php

namespace PackageName\Hideorders\Model\Plugin\Sales\Order;

class Grid {

    public static $table = 'sales_order_grid';

    public function afterSearch($intercepter, $collection) {
        if ($collection->getMainTable() === $collection->getConnection()->getTableName(self::$table)) {
            $collection->addFieldToFilter('status',array('neq' => 'canceled'));//You can write your status here
        }
        return $collection;
    }
}
3
  • Thanks its working fine Commented Feb 9, 2021 at 11:27
  • Could you please upvote this?
    – ZealousWeb
    Commented Feb 9, 2021 at 11:38
  • Could please upvote my answer? @Pandurang
    – ZealousWeb
    Commented Feb 10, 2021 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.