Php WooCommerce电子邮件附件
我创建了一个插件,可以将订单报告发送到电子邮件地址。我需要获得CSV文件中的订单信息,并将其作为电子邮件附件发送。到目前为止,我已经设法获得订单信息,但我正在努力弄清楚如何在WooCommerce电子邮件中附加文件Php WooCommerce电子邮件附件,php,email,woocommerce,attachment,Php,Email,Woocommerce,Attachment,我创建了一个插件,可以将订单报告发送到电子邮件地址。我需要获得CSV文件中的订单信息,并将其作为电子邮件附件发送。到目前为止,我已经设法获得订单信息,但我正在努力弄清楚如何在WooCommerce电子邮件中附加文件 function attach_file_woocommerce_email($attachments, $id, $object) { if($id == 'order_information_report') { $uploa
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);
我使用此代码连接到附件,因此当发送“订单信息报告”时,它会添加csv文件。然而,这似乎不起作用。我试着对if语句进行注释,但仍然不起作用
有趣的是,我在WooCommerce includes电子邮件文件夹中的电子邮件触发器上尝试了这个方法
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());
}
打印程序似乎返回了csv文件的路径。我可以在浏览器中键入该路径时下载它。关于为什么这可能无法正常工作,有什么建议吗
编辑
我忘了提到我收到了电子邮件,但由于某种原因,没有附件。当我更改插件目录而不是上传目录的路径时,它似乎工作正常
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);
如果我不得不猜测为什么在您的答案有效时失败,那么可能是您在这里使用的是
baseurl
,而不是上传目录的目录路径。在您的答案中,您使用的是插件目录的目录路径。附件只适用于文件路径,而不适用于URL。是的,当我在发布答案后打印第二个附件数组时,我想可能是这样的。嗨,谢谢你,我可以通过邮件发送附件。如果我的邮件是欢迎电子邮件,如何获取用户id?