Replies: 0
Hello,
Can we display the serial numbers under order line items in the order email like this.
I’m able to do a foreach loop to get the serial numbers but whenever I add the variable for the serial number in my order items only the first serial number shows on multiple order items. We’re using the PRO version. Is this possible to achieve?
<?php
$order_id = $order->get_id();
$serial_numbers = WC_Serial_Numbers_Query::init()->from( 'serial_numbers' )->where( 'order_id', intval( $order_id ) )->get();
foreach ($serial_numbers as $serial_number) {
$decrypted_key = WC_Serial_Numbers_Encryption::maybeDecrypt( $serial_number->serial_key );
}
foreach ($order->get_items() as $key => $lineItem) {
$product_id = $lineItem['product_id'];
$product = wc_get_product( $product_id );
echo ' $product->get_image' . <div>S/N:'. $decrypted_key .'</div>;
}
?>