Magento 2How To GuideNovember 26, 2020

How to Get Payment Method From an Order in Magento 2?

How to Get Payment Method From an Order in Magento 2?

The ‘Thank You’ page is an important page in the ecommerce sales journey. It should display maximum information about the order (s). It contributes to a better shopping experience.

Customers should be able to see all the relevant order details at any point during or after checkout. For example, if a customer wants to see the shipping charges or the payment method he/she has chosen or any order information for that matter, it should be available in the Cart page, My Orders section or on the ‘Thank You’ page.

The order information available in the default Magento 2 My Orders section or on the ‘Thank You’ page is very limited. If you want to add custom order details, you have to do it programmatically.

Here, we are going to see how to get payment method from an order in Magento 2? You may require this for multiple reasons. It all depends upon the nature of your business and customer’s requirements.

Get Payment Method For an Order in Magento 2

Following is the code to get the payment model from the order, and then get the method instance from the payment:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderIncrementId)

​​​​​​​$payment = $order->getPayment();

$method = $payment->getMethodInstance();

$methodTitle = $method->getTitle();

Where $order is an instance of Magento\Sales\Model\Order. That’s all for this tutorial. Please don’t hesitate to contact us in case of any question related to this tutorial.

Related Articles: