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 5 years, 6 months ago.

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #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,
    Tony

    Tony Scales
    #29989

    Assuming 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 Harris
    #30930

    Hi 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,
    Tony

    Tony
    #30931

    Hi 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,
    Tony

    Tony
    #30954

    hi 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 Fairlamb
    #30955

    actually 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 Fairlamb
    #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 Harris
    #30971

    Hi Stephen,

    Thanks for your advice, I will try further and see how far I get with the plugin.

    Regards,
    Tony

    Tony
    #30976

    Thanks Stephen, this worked perfectly!
    Really appreciate your assistance
    cheers,
    Joe

    Joe Fairlamb
    #30977

    Hi 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);

    Tony
    #30978

    Hi 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,
    Tony

    Tony
    #30979

    Hi 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
    i

    Joe Fairlamb
    #30980

    Hi 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,
    Tony

    Tony
    #30981

    Hi 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,
    Tony

    Tony
    #30982

    Hi 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,
    Joe

    Joe Fairlamb
Viewing 15 posts - 1 through 15 (of 21 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.