I want to change the subject line of the email I send to the store owner to put the product name in it. I saw this code to put the customer's name in front How can I adjust this code to include the product name
/* * Place it in the theme’s functions.php or custom plug-in * * Topic filter: *woocommerce_email_subject_new_order *woocommerce_email_subject_customer_processing_order *woocommerce_email_subject_customer_completed_order *woocommerce_email_subject_customer_invoice *woocommerce_email_subject_customer_note *woocommerce_email_subject_low_stock *woocommerce_email_subject_no_stock *woocommerce_email_subject_backorder *woocommerce_email_subject_customer_new_account *woocommerce_email_subject_customer_invoice_paid **/ add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2); function change_admin_email_subject( $subject, $order ) { global $woocommerce; $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = sprintf( '[%s] New customer order (# %s) from name %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name ) ; return $subject; }
Maybe we just need to make changes here
$subject = sprintf( '[%s] New customer order (# %s) from name %s %s', $blogname, $item-> ;get_name, $order->billing_first_name, $order->billing_last_name ); return $subject; }
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:
Place the code in your child theme’s functions.php file (or in a plugin). It has been tested and works fine.