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?



The problem is that option probably contains several values.

Try this code

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

  • getValues returns nothing, I already tried. Mar 6 '14 at 13:07
  • than var_dump($option) what does it contain? Mar 6 '14 at 13:07
  • Solved it another way by getting all the items from the cart and iterating those. Mar 6 '14 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 '15 at 20:19

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.