Magento 2 – How to Get Order Increment ID Using Order ID

magento2orderssales-order

Can anyone please tell me How to Get order increment id using order id in Magento 2?

Thanks.

Best Answer

You have to pass \Magento\Sales\Api\OrderRepositoryInterface in construct of your class.

protected $orderRepository;

public function __construct(
    ..., 
    \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
){
    ...
    $this->orderRepository = $orderRepository;
}

Then you can do following:

$order = $this->orderRepository->get($orderId);
$orderIncrementId = $order->getIncrementId();