Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active June 13, 2024 04:18
Show Gist options
  • Save jessepearson/543772c0fe2b42b52c3c5addae77acf9 to your computer and use it in GitHub Desktop.
Save jessepearson/543772c0fe2b42b52c3c5addae77acf9 to your computer and use it in GitHub Desktop.
This function/filter will add ics files from bookings created with WooCommerce Bookings to the Processing and Completed emails sent from WooCommerce itself.
<?php // do not copy this line
/**
* This function/filter will add ics files from bookings created with WooCommerce Bookings to
* the Processing and Completed emails sent from WooCommerce itself.
* @param arr $attachments Current array of attachments being filtered.
* @param str $email_id The id of the email being sent.
* @param obj $order The order for which the email is being sent.
* @return arr The filtered list of attachments.
*/
function jp_add_ics_to_woocommerce_emails( $attachments, $email_id, $order ) {
// The woocommerce email ids for which you want to attach the ics files.
$available = array(
'customer_processing_order',
'customer_completed_order',
);
// Check to make sure we have a match.
if ( in_array( $email_id, $available ) ) {
// Get the booking ids from the order, and get the exporter object.
$booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_id( $order->get_id() );
$generate = new WC_Bookings_ICS_Exporter;
// Go through each id and add the attachments.
foreach ( $booking_ids as $booking_id ) {
$booking = get_wc_booking( $booking_id );
$attachments[] = $generate->get_booking_ics( $booking );
// If the object is not unset, then the New Booking Email is sent twice.
unset( $booking );
}
}
return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'jp_add_ics_to_woocommerce_emails', 10, 3 );
@ajlauron
Copy link

Thanks, buddy! Do you happen to know where to change the organizer name? In the ics email, it says unknown organizer. Thanks again!

@Everard1
Copy link

Very handy, thanks. I am using woocommerce product vendors with woocommerce bookings and would like an ics to go to the vendor as well. I tried adding in vendor specific emails to the array but it did not work. Any ideas?

@GAskygirl
Copy link

This worked for me, but unfortunately I am running a setup using WPML for a multi-language site. This added three .ics files to my test email with my setup--two for the alternate language (one might be from a post revision of the translation of the purchased bookable product) and one for the primary language. If you're working with a single-language setup, this should work great. :)

@yashrankawdm
Copy link

Hi, how can i add the meeting link to the ICS files as well? any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment