4

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?

23

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.

  • Magento\Sales\Model\Order is not called from the used block. – Seventh St Jan 30 '17 at 6:00
  • $_order in the My Orders page template is a Magento\Sales\Model\Order. – Aaron Allen Jan 30 '17 at 6:11
  • forget my deleted comments. I just didn't pay attention :) – Seventh St Jan 30 '17 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 '18 at 9:21

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.