You can't just put a foreach
into the middle of a string like that. That's fundamentally broken syntax. It just doesn't work like that.
The best solution for you is to declare the loop as a separate function, like so:
function cartItemTableRows($shopper_cart) {
$output = '';
foreach($shopper_cart as $item) {
$value = $item['aantal'] * $item['price'];
$sum += $value;
$output .='<tr>
<td>'.$item["product_id"].'</td>
<td>'.$item["aantal"].'</td>
<td>€'.$item["aantal"] * $item["price"].'</td>
</tr>';
}
return $output;
}
Now you can put a call to your new function into the existing code where you're building the string:
$tableHTML = '<table>
<tr>
<td class="column-product"><strong>Productomschrijving</strong></td>
<td class="column-aantal"><strong>Aantal</strong></td>
<td class="column-prijs"><strong>Prijs</strong></td>
</tr>'.cartItemTableRows($shopper_cart).'
</table>';