0

I need to display the product custom attribute values in magento2 order details page but not display. Attributes having values in admin side. I tried both codes.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load('4');
echo '<pre>'; print_r($product->getata());

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$product = $objectManager->create('\Magento\Catalog\Api\Data\ProductInterface'); 
$product->get('4');
echo '<pre>'; print_r($product->getData());
2
  • Have you checked my answer? Jun 4, 2018 at 9:27
  • yes, but code is not working in order details page Jun 4, 2018 at 10:47

1 Answer 1

0

You can get it by this way:

$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')
    ->getProductOptionCollection($_product);

if (empty($customOptions)) { //check if product has custom options. If it doesn't go to the next product
    continue;
}

foreach($customOptions as $option) {
    $values = $option->getValues();
    if (empty($values)) { //check if option has values (Option can have values only if option type is checkbox, radio, multiselect or drop-down)
        continue;
    }

    foreach($values as $value) {
        $valueData = $value->getData(); //do whatever you want will value data
    }
}
1
  • Not working the above code. Jun 4, 2018 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.