10

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?

2 Answers 2

33

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
    Commented Jan 30, 2017 at 6:00
  • $_order in the My Orders page template is a Magento\Sales\Model\Order. Commented Jan 30, 2017 at 6:11
  • forget my deleted comments. I just didn't pay attention :)
    – Seventh St
    Commented 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
    Commented Apr 4, 2018 at 9:21
3
$_order->getPayment()->getAdditionalInformation("method_title")
2
  • Please add more details about your code for better understanding
    – Jarnail S
    Commented 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
    Commented Dec 16, 2020 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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