从Woocommerce中的名称更改新订单电子邮件通知

时间:2018-12-05 07:27:46

标签: php wordpress woocommerce orders email-notifications

新订单流程的电子邮件通知的标题为'My Blog'

我查看了Woocommerce设置,但找不到它。

任何想法如何将'My Blog'更改为'X Company' 附加图像中的红色下划线文本。

平台:Wordpress + Woocommerce

enter image description here

enter image description here

4 个答案:

答案 0 :(得分:1)

更新

您要更改的是“发件人名称”,可以使用以下方式进行更改:

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文件中。经过测试,可以正常工作。

  

然后,在电子邮件设置的电子邮件通知的“主题”字段上,您将能够替换例如:

Your {site_title} order receipt from {order_date}
     

作者

Your {shop_company} order receipt from {order_date}

答案 1 :(得分:0)

请使用此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

答案 2 :(得分:0)

转到

WooCommerce > Settings > Emails > Processing Orders.

在这里您将找到一个名为"Email Subject"的字段。在这里,将{site_title}更改为您希望其显示的内容。

或者,如果您想更改{site_title}本身的值,则转到Settings > General

在这里您将找到名为“网站标题”的字段。将其更改为您希望它出现的任何内容。

让我知道它是否有效!

答案 3 :(得分:0)

我在挖掘后发现了解决方案,这非常容易。

WooCommerce>设置>电子邮件

在底部,您可以在其中部分设置页眉和页脚文本。
很简单。
非常感谢您的帮助@LoicTheAztec

相关问题