0

I have a custom option of product enter image description here

How can I get value: 20, 30 in .phtml file. Hope anyone helps me. Thank in advance.

1 Answer 1

1

Try below code to get custom option value

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

To get custom option value title use this:

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) {
        $valueTitle = $value->getTitle();
    }
}
1
  • Thank for answer. How can I use it in my order information in admin prnt.sc/piarph
    – MichaelHa
    Commented Oct 12, 2019 at 15:26

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.