{"id":1706,"date":"2021-04-14T04:01:21","date_gmt":"2021-04-14T04:01:21","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-all-orders-of-customer-by-email-id-in-magento-2\/"},"modified":"2025-07-16T18:14:05","modified_gmt":"2025-07-16T12:44:05","slug":"get-all-orders-of-customer-by-email-id-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-all-orders-of-customer-by-email-id-in-magento-2\/","title":{"rendered":"How to Get All Orders of Customer by Email ID in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Customer retention is very important in online business. An online store owner may want to reward his loyal customer in order to build a better customer relationship.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For doing so, the store owner may require to&nbsp;<em><strong>get all orders of customer by email id in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post offers the programmatic solution for the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One can fetch the entire collection of orders along with the order date, total items, and related information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The admin may reward the loyal customer with maximum order by offering a discount or gift hamper. He can decide so by getting all the orders of a customer by their Email ID in Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is pretty complex to get a specific customer\u2019s list of orders out of the bulk of orders in\u00a0Magento 2\u00a0store. However, I\u2019ve made this task pretty simple using the below programmatic solution:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get All Orders of Customer by Email ID in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in your<strong>&nbsp;block file<\/strong>&nbsp;at&nbsp;<strong><strong>Vendor\\Module\\Block.<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Module\\Block;\n\nuse Magento\\Framework\\View\\Element\\Template;\nuse Magento\\Framework\\View\\Element\\Template\\Context;\nuse Magento\\Sales\\Model\\ResourceModel\\Order\\Collection;\n\nclass CustomerOrder extends Template\n{\n\n\n    private $data;\n\n\n    private $context;\n\n    private $orderCollectionFactory;\n\n    public function __construct(\n        Context $context,\n        Collection $orderCollection,\n        array $data = []\n    )\n    {\n        $this->orderCollection = $orderCollection;\n        $this->logger = $logger;\n        parent::__construct($context, $data);\n    }\n\n\n    public function getCustomerOrder()\n    {\n        $customerEmailId = \"abc@gmail.com\"; \/\/ pass customer Email Id\n        $customerOrder = $this->orderCollection->create()\n            ->addAttributeToFilter('customer_email', $customerEmailId)->load();\n\n        return $customerOrder->getData();\n\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Customer retention is very important in online business. An online store owner may want to reward his loyal customer in order to build a better&#8230;<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1706","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1706"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1706\/revisions"}],"predecessor-version":[{"id":18129,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1706\/revisions\/18129"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}