从 Woocommerce 中的名称更改新订单电子邮件通知
Change New Order email notification from name in Woocommerce
新订单流程的电子邮件通知标题为 'My Blog'
。
我查看了 Woocommerce 设置,但找不到。
知道如何将 'My Blog'
更改为 'X Company'
附加图像中的红色下划线文本。
平台:Wordpress + Woocommerce
请使用此 WooCommerce 挂钩 woocommerce_email_subject_new_order
更改新订单电子邮件标题。
add_filter( 'woocommerce_email_subject_new_order', 'customizing_new_order_subject', 10, 2 );
function customizing_new_order_subject( $formated_subject, $order ){
// Get an instance of the WC_Email_New_Order object
$email = WC()->mailer->get_emails()['WC_Email_New_Order'];
// Get unformatted subject from settings
$subject = $email->get_option( 'subject', $email->get_default_subject() );
// Loop through order line items
$product_names = array();
foreach( $order->get_items() as $item )
$product_names[] = $item->get_name(); // Set product names in an array
// Set product names in a string with separators (when more than one item)
$product_names = implode( ' - ', $product_names );
// Replace "{product_name}" by the product name
$subject = str_replace( '{product_name}', $product_names, $subject );
// format and return the custom formatted subject
return $email->format_string( $subject );
}
有关详细信息,请参阅此 link
转到
WooCommerce > Settings > Emails > Processing Orders.
在这里您会找到一个名为 "Email Subject"
的字段。在这里,将 {site_title}
更改为您希望它显示的任何内容。
或者,如果您想更改 {site_title}
本身的值,请转到 Settings > General
。
在这里您会找到名为网站标题的字段。将其更改为您希望它显示的任何内容。
如果有效请告诉我!
更新:
您要更改的是“发件人姓名”,可以使用以下方式进行更改:
add_filter('woocommerce_email_from_name', 'change_new_order_email_from_name', 10, 2 );
function change_new_order_email_from_name( $from_name, $email ){
if( $email->id === 'new_order' )
$from_name = __("ACME corp");
return $from_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
添加: 为电子邮件主题添加自定义占位符 (对于 woocommerce 3.2+):
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'custom_email_format_string', 20, 2 );
function custom_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{shop_company}' => __("ACME corp"),
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
Then in your email settings, on the Subject field of an email notification you will be able to replace for example:
Your {site_title} order receipt from {order_date}
by
Your {shop_company} order receipt from {order_date}
我在挖掘后找到了解决方案,非常简单。
WooCommerce>设置>电子邮件
底部有一个部分,您可以在其中添加页眉和页脚文本。
简单。
非常感谢您的帮助@LoicTheAztec
新订单流程的电子邮件通知标题为 'My Blog'
。
我查看了 Woocommerce 设置,但找不到。
知道如何将 'My Blog'
更改为 'X Company'
附加图像中的红色下划线文本。
平台:Wordpress + Woocommerce
请使用此 WooCommerce 挂钩 woocommerce_email_subject_new_order
更改新订单电子邮件标题。
add_filter( 'woocommerce_email_subject_new_order', 'customizing_new_order_subject', 10, 2 );
function customizing_new_order_subject( $formated_subject, $order ){
// Get an instance of the WC_Email_New_Order object
$email = WC()->mailer->get_emails()['WC_Email_New_Order'];
// Get unformatted subject from settings
$subject = $email->get_option( 'subject', $email->get_default_subject() );
// Loop through order line items
$product_names = array();
foreach( $order->get_items() as $item )
$product_names[] = $item->get_name(); // Set product names in an array
// Set product names in a string with separators (when more than one item)
$product_names = implode( ' - ', $product_names );
// Replace "{product_name}" by the product name
$subject = str_replace( '{product_name}', $product_names, $subject );
// format and return the custom formatted subject
return $email->format_string( $subject );
}
有关详细信息,请参阅此 link
转到
WooCommerce > Settings > Emails > Processing Orders.
在这里您会找到一个名为 "Email Subject"
的字段。在这里,将 {site_title}
更改为您希望它显示的任何内容。
或者,如果您想更改 {site_title}
本身的值,请转到 Settings > General
。
在这里您会找到名为网站标题的字段。将其更改为您希望它显示的任何内容。
如果有效请告诉我!
更新:
您要更改的是“发件人姓名”,可以使用以下方式进行更改:
add_filter('woocommerce_email_from_name', 'change_new_order_email_from_name', 10, 2 );
function change_new_order_email_from_name( $from_name, $email ){
if( $email->id === 'new_order' )
$from_name = __("ACME corp");
return $from_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
添加: 为电子邮件主题添加自定义占位符 (对于 woocommerce 3.2+):
// Only for woocommerce versions 3.2 + (up to 3.2)
add_filter( 'woocommerce_email_format_string' , 'custom_email_format_string', 20, 2 );
function custom_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;
// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
'{shop_company}' => __("ACME corp"),
);
// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
Then in your email settings, on the Subject field of an email notification you will be able to replace for example:
Your {site_title} order receipt from {order_date}
by
Your {shop_company} order receipt from {order_date}
我在挖掘后找到了解决方案,非常简单。
WooCommerce>设置>电子邮件
底部有一个部分,您可以在其中添加页眉和页脚文本。
简单。
非常感谢您的帮助@LoicTheAztec