0
$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
    }
}

I try this code but not working ?!

0

This code is working for me

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

if (!empty($customOptions->getData())) {
    foreach ($customOptions->getData() as $option) {
    print_r($option); // do whatever in your option

    }
}
  • Same result nothing ? – user70814 Aug 5 '18 at 17:14
  • exactly where you put this code – user70814 Aug 5 '18 at 17:15
  • Notice: Undefined variable: objectManager – user70814 Aug 5 '18 at 17:25
  • You have to instantiate the object manager, but as a quick action you can get it like this $objectManager= \Magento\Framework\App\ObjectManager::getInstance(); – WISAM HAKIM Aug 5 '18 at 21:14
  • ok but still not print any thing in list page – user70814 Aug 5 '18 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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