P粉2074830872023-08-19 00:32:27
Your actual code is outdated... To add the purchased product name (and quantity) to the subject of the new order email notification sent to the admin, use the following code:
add_filter('woocommerce_email_subject_new_order', 'change_email_subject_new_order', 10, 2); function change_email_subject_new_order( $formatted_subject, $order ) { $products = array(); // 初始化 // 循环遍历订单项目 foreach( $order->get_items() as $item ){ // 将格式化的产品名称和数量添加到数组中 $products[] = sprintf( '%s × %d', $item->get_name(), $item->get_quantity() ); } $count = count($products); // 产品数量 $products = implode(', ', $products); // 将数组转换为字符串 return sprintf( __('[%s] 新客户订单(#%s),%s,来自%s%s', 'woocommerce'), wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), $order->get_order_number(), sprintf( _n('产品(%s)', '产品(%s)', $count, 'woocommerce'), $products, $products ), $order->get_billing_first_name(), $order->get_billing_last_name() ); }
Place the code in your child theme’s functions.php file (or in a plugin). It has been tested and works fine.