【问题标题】:How to add HTML elements into email templates in WooCommerce?如何在 WooCommerce 中将 HTML 元素添加到电子邮件模板中?
【发布时间】:2018-07-05 16:57:09
【问题描述】:

我看过很多关于WooCommerce 电子邮件自定义的文章,但我找不到任何解释如何实际修改电子邮件页面结构的文章。对于我的项目,我需要添加包含文本和图像的新页面元素。我想像构建页面一样构建我的电子邮件。

在电子邮件模板中回显内容似乎不起作用。如果我采用templates/emails/customer-completed-order.php,在其中回显内容,然后使用Email Log plugin 预览结果,这没有任何区别:我的echos 不渲染。

WooCommerce 电子邮件真的不可能深度定制吗?

【问题讨论】:

    标签: email woocommerce


    【解决方案1】:

    转到此文件夹:

    plugin/WooCommerce/template/emails
    

    将文件夹emails复制到你的主题文件夹然后修改emailsfolder中的php文件

    如果您的更改实际上不起作用,请查看这篇文章:

    https://docs.woothemes.com/document/template-structure/

    还有一些插件可用于创建自定义电子邮件模板

    【讨论】:

    • 谢谢,但问题与模板覆盖无关。即使在修改核心 WC 模板时(为了经验)它也不起作用。至于插件我只发现codecanyon.net/item/email-customizer-for-woocommerce/8654473 不允许做我想做的事。
    • 除非您的主题已将 woocommerce 文件夹修改为其他名称,否则文件应位于 your-theme/woocommerce/emails 中。 1.您需要尝试发送真实的电子邮件,而不是依赖预览插件(它只是提出另一个故障点)和2.您需要确保您没有启用template debug mode
    【解决方案2】:

    Woocommerce 电子邮件可以自定义,但只能在一定程度上进行自定义。

    任何一封电子邮件的内容都有点复杂。

    例如电子邮件的标题部分从文件email-header.php 呈现。电子邮件的页脚部分从文件email-footer.php 呈现。同样,对于每种不同的类型,都有不同的模板文件,例如customer-invoice.phpcustomer-new-account.phpcustomer-processing-order.php 等。电子邮件的内容也从不同的钩子和函数中调用。同样,所有电子邮件元素都嵌入了内联样式。这些样式在另一个文件email-styles.php 中定义。奇怪的是,您无法在任何电子邮件模板中轻松找到此文件的引用。

    关于在电子邮件中添加其他内容/信息应该是可能的。

    【讨论】:

      【解决方案3】:

      在主题functions.php中,请创建一个两个钩子来添加新内容或应用HTML标签:

       function add_order_email_instructions( $order, $sent_to_admin )
        {
             $order_id = $order->get_id();
            if(!$sent_to_admin) 
             {
               //Your message or code
             }
            else
             {
                //Your message or code
             }
          }
         add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );
      add_filter( 'woocommerce_email_headers', 'new_order_reply_to_admin_header', 20, 3 );
      function new_order_reply_to_admin_header( $header, $email_id, $order ) 
      {
      
          if ( $email_id === 'new_order' ){
              $email = new WC_Email($email_id);
              $header = 'MIME-Version: 1.0' . "\r\n";
              $header = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
          }
          return $header;
      }
      

      【讨论】:

        猜你喜欢
        • 2014-09-13
        • 2015-01-02
        • 1970-01-01
        • 1970-01-01
        • 2020-05-18
        • 2015-05-29
        • 1970-01-01
        • 2011-11-27
        • 1970-01-01
        相关资源
        最近更新 更多