I created a plugin that sends an order report to an email address. I need to get order information in a CSV file and send it as an email attachment. So far I have managed to get order information, but I'm struggling with how to attach the file in 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);
I used this code to attach to attachments, so when "order_information_report" is sent, it adds the csv file. However, this does not seem to work. I tried commenting out the if statement, but it still didn't work.
Interestingly, I tried this on an email trigger inside WooCommerce, including the 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. , . , ?
Edit
, ,