0

I created a script to export order information into a CSV but I'm unsure on how to display the contents of the array. What I'm trying to do is capture the custom options selected for a given order and display them. I'm new to PHP so having a hard time with this. So far I was able to display just the last option from each order but not all with this...

$_options = $block->getItemOptions();
     foreach ($_options as $option) {
         $str = $option['label'] . ' : ' . $option['value'];

     }

I then stored the value of $option into an array which when checking $array the output does contain all the selected options. I'm just unsure on how to extract the label & value of each custom option from an order to display in CSV. The below code doesn't work!

$_options = $block->getItemOptions();
     foreach ($_options as $option) {
         $array[] = $option;
         $str = $array['label'] . ' : ' . $array['value'];
     }
0

In your loop, you are just overwriting what content was already contained in the variable $str. You want to append to that variable instead.

$str = ''; // initialize variable as a string
foreach($_options as $option){
    $str .= $option['label'] . ': ' . $option['value'] . ' // ';
}
echo $str;

The above is a simplistic example, but it's what you want to do.

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.