My products have a custom field called depot. I need to display this field only in admin mail notifications, not to the customer order recap or customer mail notifications.
I use this code to retrieve the custom field in email notifications :
add_action( 'woocommerce_email_order_meta', 'add_depot', 10, 3 );
function add_depot( $order, $sent_to_admin, $plain_text ){
$items = $order->get_items();
foreach ( $items as $item ){
$depot = $item->get_meta('depot');
$item['name'] = 'Dépôt: ' . $depot . $item['name'];
}
}
At the moment, it displays the field only in customer emails and not in admin emails as I would like. I think I need to use $sent_to_admin but I’m not sure how.
Thank you.
2
Answers
You can implement this hook:
If you see, the second parameter which you get in arguments is – sent to admin. So if that is true, then you can add your custom meta.
Let me know if that helps.
The
woocommerce_email_order_meta
hook has 4 arguments, via$email->id
you can target specific email notificationsSo you get: