Thank you for posting this, it helped me a lot. Just like you, I needed to retrieve EPO data from my orders, though, my structure was more complex than just one field (I have around 20 different options). I did not use it as a function because it did not work but modified your code with unserialize:
Note: EPO is now stored in wp_woocommerce_order_itemmeta table and works with key pairs
$output = '';
$epos = unserialize($yourmetavalue);
if (is_array($epos) ){
foreach ($epos as $key => $epo) {
if ($epo && is_array($epo)){
$output .= '' . $epo['name'] .': '. $epo['value'] .'<br>';
}
}
}
echo $output;
Since I wanted to exclude certain values (like comments) and have links for EPO files uploaded by the clinets this is my actual code:
$output = '';
$epos = unserialize($epodata);
if (is_array($epos) ){
foreach ($epos as $key => $epo) {
if ($epo && is_array($epo) && $epo['name'] != "Commentaire"){
if (strpos($epo['value'], 'http') === 0) {
$epo['value'] = "<a target='_blank' href='".$epo['value']."'>See file</a>";
}
$output .= '' . $epo['name'] .': '. $epo['value'] .'<br>';
}
}
}
echo $output;
Be aware that I was unable to make your code work, (skill issue). The reason I am posting here is because I have never seen anyone try to extract EPO data from the DB other than you.
Hope it can help others.