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. Commented Mar 6, 2014 at 13:07
  • than var_dump($option) what does it contain? Commented Mar 6, 2014 at 13:07
  • Solved it another way by getting all the items from the cart and iterating those. Commented 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
    Commented Jul 14, 2015 at 20:19

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.