Skip to content

Instantly share code, notes, and snippets.

@BHWD
Created July 23, 2019 15:05
Show Gist options
  • Save BHWD/bb14993455a997a74d4549155eef4ce4 to your computer and use it in GitHub Desktop.
Save BHWD/bb14993455a997a74d4549155eef4ce4 to your computer and use it in GitHub Desktop.
<?php
$order = wc_get_order('18');
$items = $order->get_items();
foreach ( $order->get_items() as $item_id => $item ) {
// Here you get your data
$custom_field = wc_get_order_item_meta( $item_id, '_tmcartepo_data', true );
//echo json_encode($custom_field);
// To test data output (uncomment the line below)
// print_r($custom_field);
// If it is an array of values
if( is_array( $custom_field ) ){
// Iterating in an array of keys/values
foreach( $custom_field as $key ){
foreach( $key as $keyy => $value ){
if (in_array('upload', $key['element'])) {
if ($keyy === 'value') {
echo '<img src="'.$value.'">';
}
}
}
}
// just one value (a string)
} else {
echo $custom_field;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment