I’ve found this question on how to display custom order meta into the order received page and into the notifications email of woocommerce. I’ve tried to do the same by refactoring the code but I’m unable to accomplish it correctly. In my case I have only three custom informations stored in product meta to display, how I need to fix the code?
// Display order custom meta data in Order received (thankyou) page
public function display_order_custom_meta( $order_id ) {
$fields_labels = array(
'selected_pdv',
'selected_date',
'selected_hour'
);
$order = wc_get_order( $order_id );
$count = 1;
// Loop through order items
foreach ( $order->get_items() as $item ){
// Loop through item quantity
for($i = 1; $i <= $item->get_quantity(); $i++ ) {
echo '<h6> '.$i . '</h6>';
echo '<table><tbody>';
// Loop through participants keys / labels pairs
foreach( $fields_labels as $label ){
$meta_key = $label;
echo '<tr><th>'.$label.':</th><td>'.$order->get_meta( $meta_key ).'</td></tr>';
}
//
echo '</tbody></table>';
}
$count++;
}
}
add_action('woocommerce_thankyou', array($this, 'display_order_custom_meta') )