【问题标题】:Change New Order email notification from name in Woocommerce从 Woocommerce 中的名称更改新订单电子邮件通知
【发布时间】:2018-12-05 07:27:45
【问题描述】:

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

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

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

平台:Wordpress + Woocommerce

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案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}
    

    【讨论】:

    • 测试了这个方法,只改变了主题,但标题与“我的博客”相同
    • @faisal 我找到了你想要改变的东西,所以我更新了我的答案,应该解决这个问题。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      前往

      WooCommerce > Settings > Emails > Processing Orders.
      

      在这里您会找到一个名为"Email Subject" 的字段。在这里,将{site_title} 更改为您希望它出现的任何内容。

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

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

      让我知道它是否有效!

      【讨论】:

      • 设置没问题,但是我重新输入试试,结果还是一样。
      【解决方案4】:

      我在挖掘后找到了解决方案,很容易。

      WooCommerce>设置>电子邮件

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

      【讨论】:

        猜你喜欢
        • 2019-01-12
        • 2022-01-03
        • 2021-12-25
        • 1970-01-01
        • 2019-09-23
        • 1970-01-01
        • 1970-01-01
        • 2019-02-02
        • 2017-09-20
        相关资源
        最近更新 更多