admin管理员组文章数量:1429841
I am trying to get the names of all the products ordered separated by a comma and added into the subject line of the new order email sent to the admin.
Here's some code I have but it's only adding in the first product name, 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;
}
I am trying to get the names of all the products ordered separated by a comma and added into the subject line of the new order email sent to the admin.
Here's some code I have but it's only adding in the first product name, 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;
}
Share
Improve this question
asked May 1, 2019 at 20:47
Nick TaylorNick Taylor
1379 bronze badges
1 Answer
Reset to default 2Since Woocommerce 3 your actual code is a bit outdated. In the following you will get all products names (coma separated) in the email subject.
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 10, 2);
function change_admin_email_subject( $subject, $order ) {
$products_names = array();
foreach ( $order->get_items() as $item ) {
$products_names[] = $item->get_name();
}
return sprintf( '[%s] New Customer Order (#%s) of %s from %s %s',
wp_specialchars_decode(get_option('blogname'), ENT_QUOTES),
$order->get_id(),
implode(', ', $products_names),
$order->get_billing_first_name(),
$order->get_billing_last_name()
);
}
本文标签: phpAdd the Name of Products Ordered to Admin New Order Email WooCommerce
版权声明:本文标题:php - Add the Name of Products Ordered to Admin New Order Email WooCommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745533471a2662166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论