WooCommerce电子邮件附件 [英] WooCommerce Email Attachment

查看:83
本文介绍了WooCommerce电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个插件,可以将订单报告发送到电子邮件地址.我需要在CSV文件中获取订单信息,并将其作为附件与电子邮件一起发送.到目前为止,我已经设法获得了订单信息,但是我正在努力弄清楚如何在WooCommerce电子邮件中附加文件.

I've created a plugin that sends an order report to an email address. I need to get the order information in a CSV file and send it as an attachment with the email. So far, I've managed to get the order information but I am struggling figuring out how to attach a file in a WooCommerce email.

function attach_file_woocommerce_email($attachments, $id, $object)
{           
    if($id == 'order_information_report')
    {
        $upload = wp_upload_dir();

        $order_csv_information = $upload['baseurl'] . '/order_information.csv';
        $attachments[]      = $order_csv_information;
    }

    return $attachments;
}
add_filter('woocommerce_email_attachments', 'attach_file_woocommerce_email', 10, 3);

我已经使用此代码挂接到附件,因此,在发送"order_information_report"时,它将添加csv文件.但是,这似乎不起作用.我尝试注释掉if语句,但仍然无法正常工作.

I have used this code to hook onto the attachments so when the "order_information_report" is being sent it adds the csv file. However this seems to not work. I tried commenting out the if statement but it still didn't work.

有趣的是,我在WooCommerce包含电子邮件文件夹中的电子邮件触发器上尝试了此操作.

Interestingly I tried this on the email trigger inside the WooCommerce includes email folder.

public function trigger($order_id) // Email Trigger
{
  if(!$this->get_recipient())
  {
    return;
  }

  $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());

  print_r($this->get_attachments());
}

print_r似乎返回了csv文件的路径.当我在浏览器中键入该路径时,可以下载它.关于为什么这可能无法正常工作的任何建议?

The print_r seemed to return the path for the csv file. I can download it when I type that path in the browser. Any suggestions on to why this may not be working correctly?

修改

我忘了提到我收到了电子邮件,但没有附件

I forgot to mention I get the email but with no attachment

推荐答案

由于某些原因,当我更改插件目录的路径而不是上载目录时,它似乎可以正常工作.

For some reason when I change the path to the plugin directory instead of the uploads directory it seems to work fine.

function attach_file_woocommerce_email($attachments, $id, $object)
{           
    if($id == 'order_information_report')
    {
        $your_txt_path = woire_get_plugin_path() . '/test.txt'; 
        $attachments[] = $your_txt_path;
    }

    return $attachments;
}
add_filter('woocommerce_email_attachments', 'attach_file_woocommerce_email', 10, 3);

这篇关于WooCommerce电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆