How to Get Orders by Payment Method

We continue also this year our journey exploring Magento 2. In this post we will see how we can get orders that were made by a specific payment method. Let's have a look together.

In our example we will use the order repository to get a list of all orders by a specific payment method. Unfortunately the payment method data is not part of the order repository data, that means that we will add this information as an extension attribute. Below we define that extension attribute in the extension_attributes.xml.

Now we will get all orders that were made by the Magento payment method checkmo. In our example block class below you can see how we build our search criteria filtering by our extension attribute and how we pass them to the order repository getList function.

Feel free to share this post and ask your questions in the comments below.

Till next time!

DigitalOcean Referral Badge