ics file for individual events in a series?

WordPress Event Management, Calendars & Registration Forums General Question ics file for individual events in a series?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 6 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #31110

    We have an event which has multiple dates – How can we create an ics file for each of these events so users who book tickets for this certain date can download the correct ics file?

    Kelton Turvey
    #31127

    The plug-in can generate an ics file for the whole series of an individual event, but not individual dates of an event.

    If you’re familiar with the iCal specification you could build a string with the details and then attach that as a string attachment. It depends on whether you want to provide a URL which points to an ics feed or whether you’re happy to attach it directly to the email.

    To do the latter is a bit involved because WordPress’ wp_mail() only supports attaching files, not strings generated at runtime .However you can use the following code:

    <?php
    class Myprefix_iCal_Email_Attacher{
    
        protected $booking_id = false;
    
        function setup( $attachments, $booking_id ){
            $this->booking_id = $booking_id;
            add_action( 'phpmailer_init', array( $this, 'attach_ical' ), 10 );
            add_action( 'phpmailer_init', array( $this, 'cleanup' ), 11 );
            return $attachments;
        }
    
        function attach_ical( $phpmailer ){
            if( $this->booking_id ){
                $event_id    = eo_get_booking_meta( $this->booking_id , 'event_id' );
                $occurrence_id    = eo_get_booking_meta( $this->booking_id , 'occurrence_id' );
                $title = esc_attr( get_the_title( $event_id ) );            
                $filename    = sanitize_file_name( $title.'-'.$this->booking_id.'.ics' );
                $ical_string = $this->get_ical( $event_id, $occurrence_id ); 
                $phpmailer->AddStringAttachment( $ical_string, $filename );
                $this->booking_id = false;
            }
        }
    
        function get_ical( $event_id, $occurrence_id ){
            return "...ics string feed for this event date...";
        }
    
        function cleanup(){
            remove_action( 'phpmailer_init', array( $this, 'attach_ical' ), 10 );
        }
    
    }
    $ical_attacher = new Myprefix_iCal_Email_Attacher();
    add_filter( 'eventorganiser_booking_confirmed_email_attachments', array( $ical_attacher, 'setup' ), 10, 2 );
    

    All you would need to implement is the get_ical() method.

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 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.