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(); // 初始化 // 循環(huán)遍歷訂單項(xiàng)目 foreach( $order->get_items() as $item ){ // 將格式化的產(chǎn)品名稱和數(shù)量添加到數(shù)組中 $products[] = sprintf( '%s × %d', $item->get_name(), $item->get_quantity() ); } $count = count($products); // 產(chǎn)品數(shù)量 $products = implode(', ', $products); // 將數(shù)組轉(zhuǎn)換為字符串 return sprintf( __('[%s] 新客戶訂單(#%s),%s,來自%s%s', 'woocommerce'), wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), $order->get_order_number(), sprintf( _n('產(chǎn)品(%s)', '產(chǎn)品(%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.