Are you a Magento 2 developer looking for a quick and easy way to fetch the order status label in your custom module? Look no further! 🛍️💻
👉 Follow these simple steps to get the order status label:
Step 1: Initialize the necessary dependencies
<?php
use Magento\Sales\Model\OrderFactory;
use Magento\Framework\App\Helper\Context;
protected $orderFactory;
public function __construct(
Context $context,
OrderFactory $orderFactory
) {
parent::__construct($context);
$this->orderFactory = $orderFactory;
}
Step 2: Fetch the order status label
<?php
public function getOrderStatusLabel($orderId)
{
$order = $this->orderFactory->create()->load($orderId);
$statusLabel = $order->getStatusLabel();
return $statusLabel;
}
Step 3: Utilize the function in your custom module
<?php
$orderId = 123; // Replace with your desired order ID
$orderStatusLabel = $this->getOrderStatusLabel($orderId);
echo "Order Status Label: " . $orderStatusLabel;
That's it! You've successfully obtained the order status label in Magento 2. Now you can display this information wherever you need it in your custom modules or templates.
Happy coding! 🚀👨💻