• Resolved thetankgirl

    (@thetankgirl)


    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>’

Viewing 1 replies (of 1 total)
  • Hi @thetankgirl,

    Sorry for the wait on response for this! You can check out this Stackoverflow thread for how to add product attributes including location to an email.

    I will go ahead and close this thread due to the age, but if you are still having issues please open a new thread and let us know!

Viewing 1 replies (of 1 total)
  • The topic ‘Sort new order e-mail products by custom attribute’ is closed to new replies.