0

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 );
  • it's added in the construct, therefore it will be added only on instantiation, what is the object variable? – inarilo Nov 24 '17 at 18:58
0

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.

It's not a 'work around'. That's the correct way to do it. But there is a shorter way to do the same thing.

WordPress has a function called __return_empty_array() that just returns array(). So if you want to empty an array with a filter, you can just use that:

add_filter( 'woocommerce_bookings_emails_ics', '__return_empty_array' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.