8

I want to show payment method of an order in My Orders customer page.

I have tried use echo $_order->getPaymentMethod(), it gives NULL variable.

I also tried echo $block->getpaymentsCollection()->getTitle(), it shows messy looks without error.

So, what is correct way to show payment method title of an order?

3 Answers 3

32

Get the payment model from the order, then get the method instance from the payment:

    $payment = $order->getPayment();
    $method = $payment->getMethodInstance();
    $methodTitle = $method->getTitle();

Where $order is an instance of Magento\Sales\Model\Order.

4
  • Magento\Sales\Model\Order is not called from the used block.
    – Seventh St
    Jan 30, 2017 at 6:00
  • $_order in the My Orders page template is a Magento\Sales\Model\Order. Jan 30, 2017 at 6:11
  • forget my deleted comments. I just didn't pay attention :)
    – Seventh St
    Jan 30, 2017 at 6:31
  • I get this error. Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: Area code is not set can you please help me @AaronAllen
    – Joey
    Apr 4, 2018 at 9:21
2
$_order->getPayment()->getAdditionalInformation("method_title")
2
  • Please add more details about your code for better understanding
    – Jarnail S
    Dec 15, 2020 at 22:02
  • What? If You have Magento\Sales\Model\Order object, You can get payment method title using line above. What do You want to know more? You don't need payment method instance. Just get method title from additional information.
    – Norton
    Dec 16, 2020 at 23:52
0

The answear of @Norton is correct. Work for me.

New contributor
Cleiton Garcia is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.