I have added a Column on Order Table is_hidden, If an Order is set is_hidden = 1 then I want to hide that order from Customer Order List in Customer Account on Frontend.

How can I add aditional filter on the Order Collection without updating Core File.

2 Answers 2


You can field your order Collection using another way Magento Plugin.

Create after Method {afterGetOrders} on getOrders() at plugin class and filter by is_hidden = 1.

Create di.xml and code Like:

    <type name="Magento\Sales\Block\Order\History">
      <plugin name="{pluginName}" type="{VendorName}\{Modulename}\Plugin\HistoryPlugin" sortOrder="1" disabled="false" />

Plugin Class:

namespace {VendorName}\{Modulename}\Plugin;

class HistoryPlugin
   public function afterGetOrders(\Magento\Sales\Block\Order\History $subject, $result)
    if($result &&  $result->getSize() > = 1){
      return $result->addFieldToFilter('is_hidden',['null'=> true]);    
       return $result;
  • Appliying $result->addFieldToFilter('is_hidden',['neq'=> 1]); hides all the orders, including the one with is_hidden = NULL Nov 30, 2018 at 7:36
  • is_hidden is field boolean field ?
    – Amit Bera
    Nov 30, 2018 at 7:38
  • And When I do $result->addFieldToFilter('is_hidden',['eq'=> 1]); Equals to, It does gives the list of is_hidden = 1 items Nov 30, 2018 at 7:38
  • yes is_hidden is a boolean field, and it include value NULL 0(where NULL and 0 are not hidden), and 1 Nov 30, 2018 at 7:40
  • 1
    Pagination is not updated from the above solution...? Dec 13, 2018 at 7:08

You need to override Magento\Sales\Block\Order\History in your custom module by using preference.

in your custom extension's etc/di.xml add preference

<preference for="Magento\Sales\Block\Order\History" type="YouPackage\YourModule\Block\Order\History" />

Note: You can also use plugin afterGetOrders() if you find that more suitable.

Now in overridden class, you can add filter to below method


Use addFieldToFilter('is_hidden', 0); to get orders only with is_hidden set to 0.

Or you can also try not in array like below

$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
                ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
                ['nin' => [1]]

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.