I am using a WooCommerce plugin and it has a filter for emails I wish to override. The filter is declared as such:
public function __construct() {
add_filter( 'woocommerce_email_attachments', array( $this, 'attach_ics_file' ), 10, 3 );
}
As part of a Class:
class WC_Booking_Email_Manager
The function is:
public function attach_ics_file( $attachments, $email_id, $booking ) {
$available = apply_filters( 'woocommerce_bookings_emails_ics', array( 'booking_confirmed', 'booking_reminder' ) );
if ( in_array( $email_id, $available ) ) {
$generate = new WC_Bookings_ICS_Exporter;
$attachments[] = $generate->get_booking_ics( $booking );
}
return $attachments;
}
This simply attaches an .ics calendar file to emails. I don't want this to occur.
In my functions.php, I tried:
remove_filter( 'woocommerce_email_attachments', array( $GLOBALS['WC_Booking_Email_Manager'], 'attach_ics_file' ), 10,3);
But this does not work.
My question is how do I stop attachements from occuring by overriding the function, but only in the context of this plugin? i.e. There are other plugins that make attachments and I do not want to stop them from doing so.
Edit
The following code is work around by using the filter in the code above and by returning an empty array. It is placed in functions.php of your theme.
function woocommerce_bookings_emails_ics_edits( $array ) {
return array();
}
add_filter( 'woocommerce_bookings_emails_ics', 'woocommerce_bookings_emails_ics_edits', 10, 1 );