I try to get the names of all the ordered products separated by a comma and added to the subject line of the new order email sent to the administrator.
My code which I've got but it just adds in the name of the first product, not all of them```
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject( $subject, $order ) {
global $woocommerce;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item->get_name();
}
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$subject = sprintf( '[%s] New Customer Order (#%s) of '.$product_name.' from %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name);
return $subject;
}