---
title: "How to get all Orders of Customer by Email id in Magento 2"
url: "https://magecomp.com/blog/get-orders-customer-email-id-magento-2/"
date: "2019-02-18T15:30:44+00:00"
modified: "2025-02-22T11:04:10+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 342
reading_time: "2 min read"
summary: "Hello Magento Folks,"
description: "Having thousands of orders inside your Magento 2 store makes difficult to find particular order information. Especially when you are looking for desired info..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: Create Separate Column for Additional Attribute While Export Product"
    url: "https://magecomp.com/blog/magento-2-create-separate-column-for-additional-attribute-while-export-product/"
  - title: "How to Get Product Stock Information in Magento 2"
    url: "https://magecomp.com/blog/get-product-stock-information-magento-2/"
  - title: "How to Expand default Layered Navigation Category Filters in Magento 2"
    url: "https://magecomp.com/blog/expand-default-layered-navigation-category-filters-magento-2/"
---

# How to get all Orders of Customer by Email id in Magento 2

_Published: February 18, 2019_  
_Author: Dhiren Vasoya_  

![How to get all orders of customer by email id in Magento 2 2](https://magecomp.com/blog/wp-content/uploads/2019/02/How-to-get-all-orders-of-customer-by-email-id-in-Magento-2-2-1024x332.webp)

Hello Magento Folks,

Having thousands of orders inside your Magento 2 store makes it difficult to find particular order information. Isn’t it? Several times it happens to you when you are looking for desired information that isn’t possible to look at using the default backend search.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)
For example, you have one customer email id and you want to know how many orders are placed inside your Magento 2 store using that particular email by your registered customer.

We, Magicians, believe that nothing is impossible, so we came up with one super-duper script that will allow you to fetch all orders programmatically. But keep in mind that this script will only help you to fetch registered customer’s orders, not for guest customers. To do the same, we need to specify the customer order id and customer id to get all the details of a particular order.

```
<?php
namespace VENDOREXTENSIONBlock;

use MagentoBackendBlockTemplateContext;
use MagentoFrameworkEventObserverInterface;

class Ordersfromemail extends MagentoFrameworkViewElementTemplate
{
      protected $resourceConnection;
      protected $customerSes;
      protected $ordersales;

      public function __construct(Context $context,
         MagentoFrameworkAppResourceConnection $resourceConnection,
         MagentoCustomerModelSession $customerSes,
         MagentoSalesModelOrder $ordersales)
      {
           $this->resourceConnection = $resourceConnection;
           $this->customerSession = $customerSes;
           $this->orderSales = $ordersales;
           parent::__construct($context);
       }

       public function getCustomerOrderCollection()
       {
           $connection = $this->resourceConnection->getConnection();
           $customerSession = $this->customerSession->create();
           if ($customerSession->isLoggedIn())
           {
               $customer_email = $customerSession->getCustomer()->getEmail();
               $order_collection = $this->$ordersales->create()->getCollection()->addAttributeToFilter('customer_email', $customer_email);
               foreach ($order_collection as $order)
               {
                   echo "Order Id: ". $order->getEntityId();
                   echo "Customer Id: ".$order->getCustomerId();
               }
           }
        }
}
```

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

That’s it! Simply create one file that contains above code in your root folder and simply access the file by navigating through URL. You are free to play and manipulate this according to your need for finding records.<br ?–>
That’s it for today, Let us know if you are facing an issue while implementing using this code by commenting below.

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)
Happy Coding!


---

_View the original post at: [https://magecomp.com/blog/get-orders-customer-email-id-magento-2/](https://magecomp.com/blog/get-orders-customer-email-id-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-04 02:25:34 UTC_  
