How can I send an attachment with my email?
-
How would I go about attaching a file to the order complete email?
I have my file location, but I have no idea how I would attach a file to the email generated in woocommerce.How would I go about adding something like this?
-
May be you want to have a look at this
http://www.woothemes.com/products/email-attachments/
http://docs.woothemes.com/document/email-attachments/Yeah I found that one. But I’d rather have a hardcoded sollution.
Since the file is generated within the code, and the file is generated per order.I found the part that send the email, this uses the normal wp_mail class. Which should allow an attachment to be send. But I’m having a hard time decrypting the construction, and how to fill the attachment variable via the normal template.
I see,
may be you want to have a look at this filter
woocommerce_email_attachments
and try to attach your attachment files via this?
I found this in class-wc-emails.php
function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments , $content_type = 'text/html' ) { $attachments = array(WP_CONTENT_DIR . '/uploads/invoice.pdf'); //my added code // Set content type $this->_content_type = $content_type; // Filters for the email add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); // Send wp_mail( $to, $subject, $message, $headers, $attachments ); // Unhook filters remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); }
I found this piece of code, where I added in my $attachments variable. But for some reason that doesn not work.
I’m at a loss here.:), first of all don’t hardcode anything into the core (in this case woocommerc) this is technically, morally wrong (and may even kill kittens every time this code runs on your website :D).
So that’s wrong, and secondly your code is incorrect.
I noticed it is incorrect since it still don’t have any delicious attachments in my email inbox, what I can’t figure out is why.
I suggest you explore the filter
add_filter(‘woocommerce_email_attachments’,’handle_my_auto_email_attachments’), 10, 2);
function handle_my_auto_email_attachments($attachment = “”, $emailtype = ”){
//do your stuff here
}I wish I had a working example, but I don’t have it :).
Note: I suggest you try to buy the “Email Attachemnts” plugin from woothemes and see how they did it and that will surely help you achieve what you want.
I’ll look in to that, if I can’t find my solution there I’ll probably do your second suggestion.
Thanks for the input =)No problem welcome!. 🙂
- The topic ‘How can I send an attachment with my email?’ is closed to new replies.