Apologies for the following question, as my PHP knowledge isn't hugely strong, But having google'd around, i can't seem to find a solution, or an explanation as to how i could complete this
I have a custom function in Wordpress with WooCommerce which fires off on order complete.
The idea is each item has a custom field for supplier, and a suppliers e-mail address, upon a completed order, we'd like to send an e-mail to that supplier requesting they ship those items direct to the customer.
Below is my code currently
$order = new WC_Order( $order_id );
$items = $order->get_items();
$address = $order->get_formatted_shipping_address();
$totalprice;
$str = "";
foreach ( $items as $item ) {
$supplier = get_post_meta( $item['product_id'], 'Supplier', true );
$supplier_email = get_post_meta( $item['product_id'], 'Supplier_Email', true );
$str .= $product_name = $item['name']." ";
$str .= $product_id = $item['product_id']." ";
$pprice = $item['price'];
$name = $item['name'];
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$to = array("$supplier <$supplier_email>");
$subject = "Please dispatch" + $name;
$content = "Please send the following item
".$str;
$status = wp_mail($to, $subject, $content, $headers);
}
Which works, however, if we have say 4 items, with 1 item being some 'supplier X' and 3 items being from 'supplier Y' we're sending out 3 individual e-mails to supplier X, As opposed to one e-mail, which lists all items.
I'm thinking that i need to get each $supplier_email from this foreach, into it's own array - and then send an e-mail that way? But i can't seem to get it to work thus far, Could anyone help?
Thanks!