• Hey there,

    Since the last update it looks like the plugin interferes with the woocommerce_email_attachments filter I use to add some manual attachments to some products. My code in functions.php is no longer executed when “WooCommerce PDF Invoices & Packing Slips” plugin is activated:

    add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 10, 3 );
    
    function add_woocommerce_attachments_for_certain_product ( $attachments, $email_id, $email_order ){
      $product_id1 = 1;
      $product_id2 = 2;
    
      if( $email_id === 'customer_completed_order' ){
        $order = wc_get_order( $email_order );
        $items = $order->get_items();
    		$temp = false;
        foreach ( $items as $item ) {
    
          if ( $product_id1 === $item->get_product_id() ) {
            $attachments[] = get_stylesheet_directory() . '/special1.pdf'; // Child theme
          	$temp = true;
    	  }
    	if ( $product_id2 === $item->get_product_id() ) {
            $attachments[] = get_stylesheet_directory() . '/special2.pdf'; // Child theme
           $temp = true;
    	
    	}
    		
    
        }	
    	  
    	if 	( $temp === false) {
    		$attachments[] = get_stylesheet_directory() . '/standard.pdf'; // Child theme
    	}
      }
      return $attachments;
    }

    Is there a solution for this problem? I had to manually downgrade the plugin so that my store could continue to perform the desired functions.

    Thanks in advance

    Best regards
    Ray

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Ray,
    That’s strange, we have not made any changes to how we utilize that filter.
    What version did you downgrade to?

    One thing you could try is to hook your custom function later:

    
    add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 99999, 3 );
    
    Thread Starter Raysn

    (@schulhilfe)

    My current workaround is to attach the invoice to the customer processing order email so that the attachments for the customer_completed_order are not “blocked”. But there is certainly a better solution.

    Thread Starter Raysn

    (@schulhilfe)

    Hey Ewout,

    just tried to hook the function later, but with the change only the attachment specified in the functions.php was sent, the PDF invoice was apparently no longer attached. strange…

    Plugin Contributor Ewout

    (@pomegranate)

    That is all the more strange indeed. Is it possible that for some reason something in your setup only allows for one attachment at a time? Are you using a third party plugin for email delivery?

    You wrote:

    I had to manually downgrade the plugin so that my store could continue to perform the desired functions.

    What version of WooCommerce PDF Invoices & Packing Slips did you downgrade to?

    Thread Starter Raysn

    (@schulhilfe)

    Is it possible that for some reason something in your setup only allows for one attachment at a time? Are you using a third party plugin for email delivery?

    I can’t rule that out, but it worked about a month ago. There were 3 PDFs attached per e-mail: 2 via the filter in functions.php and 1 pdf invoice via the plugin. I deactivated all plugins one by one and tested in each case whether the code in the functions.php works. Only after I had deactivated “PDF Invoices & Packing Slips”, the code was executed and the respective files were attached.

    What version of WooCommerce PDF Invoices & Packing Slips did you downgrade to?

    When I wrote this, I thought it could work that way. But when I downgraded to the plugin version of October 13th, it unfortunately didn’t work anymore either. Then I suspected a change in the latest WooCommerce update and downgraded WooCommerce to the version of 10/13/2020 ( my last backup) – also unfortunately without success.

    As I said, my current workaround is to send out the PDF invoice with the order confirmation and manually attach the additional PDFs to the “Order Complete” e-mail template. But of course it would be nicer if all PDFs could be attached in one e-mail.

    Maybe we’ll get to the solution of the mystery.

    Best Regards
    Ray

    Plugin Contributor Ewout

    (@pomegranate)

    It’s quite a mystery indeed, Ray!
    The fact that putting your filter last overrules the PDF invoice attachments does seem to confirm that for some reason your setup doesn’t allow for multiple attachments. You didn’t answer this question: Are you using a third party plugin for email delivery?

    And perhaps a way to test this hypothesis: can you send multiple attachments with your custom filter? Or does this also only send 1 at a time?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Not working with woocommerce_email_attachments filter anymore’ is closed to new replies.