1

How can I get the value of a custom option text field called "My Option"? This is what I have so far:

foreach($product->getOptions() as $option) {
    $optionTitle = $option->getTitle();

    if(preg_match('/.*my option.*/i', $optionTitle)) {
        //How can I get the value here? I tried:
        $optionValue = $option->getValue();
        $optionValue = $option['value'];
    }
}

The $optionValue var is always empty. Is that the correct way?

Thanks!

1

1 Answer 1

2

The problem is that option probably contains several values.

Try this code

foreach ($option->getValues() as $oValue) {

}
4
  • getValues returns nothing, I already tried. Mar 6, 2014 at 13:07
  • than var_dump($option) what does it contain? Mar 6, 2014 at 13:07
  • Solved it another way by getting all the items from the cart and iterating those. Mar 6, 2014 at 13:17
  • This answer wold return the Values of a Drop Down or similar. The question is asking to return the value of a text field (assuming the text field has a value).
    – NotJay
    Jul 14, 2015 at 20:19

Your Answer

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

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