get payment method title of an order
-
15-04-2021 - |
Question
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?
Solution
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
.
OTHER TIPS
$_order->getPayment()->getAdditionalInformation("method_title")
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange