@andyzz is that in the items loop part of the invoice (foreach( $items as $item_id => $item )
? An order can have multiple items so you can’t rely on $item_id
outside of an items loop. It also looks like you want to look at the product ID ($item['product_id']
) rather than the item ID. In a separate location you could initiate your own (code assumes this is below the actual items list in the invoice):
<?php
foreach( $items as $item_id => $item ) {
switch ($item_id) {
case 16:
echo '<img src="https://example.com/wp-content/uploads/test1.png" />';
break;
case 17:
echo '<img src="https://example.com/wp-content/uploads/test2.png" />';
break;
default:
// for debugging only:
echo "not a known item: {$item['product_id']}"
break;
}
}
?>
As a simple first check (that assumes your orders are always only one product) you could also us $item['product_id']
instead of $item_id
in your original code.
By the way I strongly recommend using server paths rather than URLs, which is more reliable and much faster that loading it over the internet:
printf( '<img src="%s/uploads/test2.png" />', untrailingslashit( WP_CONTENT_DIR ) );
Let us know if that helps!
Ewout