Magento 2.2 – Get Product Attribute Value in Order Detail Admin

magento2magento2.2product-attributesales-order

How to show product attribute value in order detail in Magento 2.2.6?
I already tried below code but not working:

File Path:

public_html/vendor/magento/module-sales/view/adminhtml/templates/items/column/name.phtml

$_item->getProduct()->getAttributeText('attribute_code');
$_item->getProduct()->getProductAttribute('attribute_code');

Need Help.

enter image description here

Best Answer

You can get product attribute value using $objectmanager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productId = $_item->getProduct()->getId();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
echo $product->getData('attribute_code');

You can also try this code as well ( For select option attribute )

echo $product->getResource()->getAttribute('attribute_code')->getFrontend()->->getValue($product);
Related Topic