Sort new order e-mail products by custom attribute
-
I have made a custom new order e-mail for ourselves, with info about the ordered products. I need to get them to sort by the custom attribute ‘location’. How do I achieve this?
This piece works, but does not sort the products by location. Everytime I try something I end up with an empty or weird looking order-email:
` <table border=1px;>
<tr>
<td>Locatie</td>
<td>Naam</td>
<td>Gewicht</td>
<td>Aantal</td>
<td>Barcode</td>
</tr><?php
// Loop though order line items
foreach ($order->get_items() as $item_id => $item ) {
?><tr>
</td>
<?php
// Get the WC_Product Object instance
$product = $item->get_product();
$productlocation = $product->get_attribute(‘locatiecode’);
echo $productlocation;
?>
</td><td>
<?php
// PRODUCT NAME
$product_name = $item->get_name();
echo $product_name;
?>
</td>
<td>
<?php
// Get the WC_Product Object instance$weight = $product->get_weight();
if($weight == 0){
echo ” “;
} elseif($weight < 1){
$_weightstr = number_format($weight*1000,0) . ”
Gram”;}else {
$_weightstr = number_format($weight, 1, ‘,’, ”) . ” Kilo”;}
if ( $product->has_weight() ) {
echo ‘<div class=”product-meta”>’ . $_weightstr . ‘</div>
</br>’;
}
?>
</td>
<td>
<?php
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
echo $quantity;
?>
</td>
<td>
<?php
$productbarcode = $product->get_attribute(‘barcode’);
echo $productbarcode;
?>
</td>
</tr>
<?php}
?>
</table>’
- The topic ‘Sort new order e-mail products by custom attribute’ is closed to new replies.