我正在尝试获取所有订购产品的名称,这些名称用逗号分隔,并添加到发送给管理员的新订单电子邮件的主题行中。
以下是我的一些代码,但它只添加了第一个产品名称,而不是全部:
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;
}