Reputation: 3
We are preparing a template for factory QC. The template is automatically filled with all the order information and it will then be printed for their use.
This is a part of the template where the order meta items are listed, whenever we try to get the order items we get all details, we need to extract them each one by one
<table width="100%" border="0" cellpadding="7" cellspacing="0" style="text-transform: uppercase; font-size: 12px;">
<?php foreach ( $this->get_order_items() as $item_id => $item ) ?>
<tr>
<td width="35%">
Order No:
</td>
<td width="65%" style="font-weight: bold; ">
#F1-<?php $this->order_number(); ?>
</td>
</tr>
<tr>
<td>
Model:
</td>
<td style="font-weight: bold; ">
<?php echo $item['meta']; ?> //order items
</td>
</tr>
<tr>
<td>
Design:
</td>
<td style="font-weight: bold; ">
<?php echo $item['name']; ?> // product name
</td>
</tr>
</table>
The $item['meta'] gives us the following
MODEL: A4
YEAR: 2022
MAKE: Audi
COLOR: BLACK
LINE COLOR: ORANGE
We only need the model for the model row, we will put the color information and year in another table lets say. How can we extract the model in this case
<?php $item_meta = $item['meta']; ?>
<?php foreach ($item_meta as $meta_id => $meta) ?>
<?php echo $meta['Model']; ?>
We tried to use this to go through the elements one by one and get the value by meta key but it is always empty.
Edit:
We were able to get the value for Model using
wc_get_order_item_meta( $item['item_id'], 'Model' );
Upvotes: 0
Views: 186
Reputation: 11
You just need to put the 2-d array structure there as you can access the model from the items just like that.
$item['meta']['Model']
Upvotes: 1