Default PDF attach to booking email
WordPress Event Management, Calendars & Registration › Forums › General Question › Default PDF attach to booking email
This topic contains 20 replies, has 5 voices, and was last updated by Stephen Harris 6 years, 3 months ago.
-
AuthorPosts
-
February 23, 2018 at 9:38 am #29979
Hi Stephen,
I read in the forum there is a code to attach a pre-made default PDF to the confirmation / booking email the buyer receives.
Please can I have a copy of the code.Thanks.
Regards,
TonyTony ScalesFebruary 24, 2018 at 9:44 pm #29989Assuming it’s a pre-existing file, that is somewhere on your server:
add_filter( 'eventorganiser_booking_confirmed_email_attachments', function($attachments, $booking_id) { $attachments[] = '/absolute/path/to/file/to/attach.pdf'; return $attachments; }, 10, 2);
Stephen HarrisJune 11, 2018 at 1:35 pm #30930Hi Stephen,
Thank you for the code. I now have the PDF I wish to add to the ticket. I went to continue, but cannot work out where I need to add the code.
Please can you tell me to which file I should add it and where in the file.Thanks.
Regards,
TonyTonyJune 11, 2018 at 3:54 pm #30931Hi Stephen,
I tried adding the code to the functions file. That did not add the attachment to the ticket.
I find ‘eventorganiser_booking_confirmed_email_attachments’ is called in these files: bookings.php and booking-actions.php.
I assume I need to add the code to one of these files, but which file?So far I have tried this in the functions.php:
add_filter( ‘eventorganiser_booking_confirmed_email_attachments’, function($attachments, $booking_id) {
$attachments[] = ‘https://www.mydomain.com/wp-content/uploads/2018/06/huiswerk_1dag_autotheorie.pdf’;
return $attachments;
}, 10, 2);Thanks.
Regards,
TonyTonyJune 16, 2018 at 6:34 am #30954hi all, I am also looking to implement this PDF attachment to the booking confirmation, however Id like to complicate it even more by using a conditional to decide whether to add one or both of two different PDF’s.
In my situation the client is asked two yes/no questions via radio buttons in the booking form. If they answer yes to either of them I would like to attach a pdf. If they answer yes to both I would like to attach two pdfs.
Is this possible, and if so can someone give me a snippet to do it? Much appreciated!
Joe FairlambJune 16, 2018 at 9:24 am #30955actually if its easier, which I assume it is, Im happy to just include a block of text in the confirmation email along with a link to the PDF(s) – just need to figure out how to conditionally display the text based on the Yes/No value of the radio buttons in the form?
Joe FairlambJune 18, 2018 at 9:32 pm #30966@Tony
The code should go in a custom plug-in or you can put it in an file in
wp-content/mu-plugins
. I think the reason it’s not working for you is because it needs to a file path not a URL.@Joe,
When creating the custom fields they would have been assigned an ID each. You can get the value the user entered for that field as follows:
$value = eo_get_booking_meta( $booking_id, "meta_<id>", true );
where
<id>
is replaced by the ID of the field. You an use that in the above snippet (assuming field IDs of 123 and 456):add_filter( 'eventorganiser_booking_confirmed_email_attachments', function($attachments, $booking_id) { $value123 = eo_get_booking_meta( $booking_id, "meta_123", true ); $value456 = eo_get_booking_meta( $booking_id, "meta_456", true ); if($value123 == 'yes'){ $attachments[] = '/absolute/path/to/file/to/attach123.pdf'; } if($value456 == 'yes'){ $attachments[] = '/absolute/path/to/file/to/attach456.pdf'; } return $attachments; }, 10, 2);
Please note, that ‘yes’ might not be the correct string to compare against: it will depend on the label you assigned the field.
Stephen HarrisJune 19, 2018 at 11:23 am #30971Hi Stephen,
Thanks for your advice, I will try further and see how far I get with the plugin.
Regards,
TonyTonyJune 19, 2018 at 1:23 pm #30976Thanks Stephen, this worked perfectly!
Really appreciate your assistance
cheers,
JoeJoe FairlambJune 19, 2018 at 2:13 pm #30977Hi Stephen,
I have continued, but still no pdf file is attached to the ticket.
My complete mu-plugin I have tried using is below.I have tried these different absolute paths:
/aa/huiswerk_1file.pdf
aa/huiswerk_1file.pdf
../../aa/huiswerk_1file.pdf
The PDF is in a directory named “aa” in the root.Please can you help me further. I’m just not getting it..
Regards,
Tony<?php
- Plugin Name: ssdag-eventorganiser-attachment
- Description: Adds an definded attachment to the ticket.
- Author: me
// Turn off the author credit in the site footer
add_filter( ‘primer_author_credit’, ‘__return_false’ );
add_filter( ‘eventorganiser_booking_confirmed_email_attachments’, function($attachments, $booking_id) {
$attachments[] = /’aa/huiswerk_1file.pdf’;
return $attachments;
}, 10, 2);TonyJune 19, 2018 at 2:19 pm #30978Hi Joe,
Please can you say how you get this to work.
I have tried a mu-plugin file, using the above code from my last post to Stephen
I just fail every time.Regards,
TonyTonyJune 19, 2018 at 2:58 pm #30979Hi Tony, in my case I put the code in my themes functions.php file although I understand this is not the recommended best option it should work.
I had a few issues getting the absolute path correct and ended up having to include the entire path all the way back to the highest level of the hosting package, not just the wordpress install or public_html root directory.
for example my first attempt I included /public_html/wp-content/uploads/example.pdf which didnt work, then changed to /home/hosting/public_html/wp-content/uploads/example.pdf
iJoe FairlambJune 19, 2018 at 3:37 pm #30980Hi Joe,
Thanks for your help.
I will try some other absolute paths as per your examples and see if that helps.
Did you need to add anything extra to the confirmation email for it to include the attachment?Regards,
TonyTonyJune 19, 2018 at 4:25 pm #30981Hi Stephen,
I am still struggling with the attachment file.
I have tried by following Joe’s advise with the absolute path as he has shown me in his post, starting with the very top directory beyond the standard “public_html” directory.The website’s hosting for this project I am working on, the highest directory in I can call is /web/. After speaking with the hosting provider I find out /web/ is not my top directory, there are a few above /web/, but on the shared hosting I am not able to use them.
My question:
Is there another way to write the correct path to attach the pdf file?
Could the WP ‘ABSPATH’ be used somehow to achieve my goal?
Or is there another way I can attach a PDF to the booking confirmation.Thanks.
Regards,
TonyTonyJune 20, 2018 at 1:11 am #30982Hi Tony,
I didnt have to do anything with the confirmation email to make the attachment work, in my case it was only getting the absolute path correct.
Good luck!
Cheers,
JoeJoe Fairlamb -
AuthorPosts