Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter( 'woocommerce_email_attachments', 'my_child_attach_invoice_pdf', 10, 3 );
  4.  
  5. function my_child_attach_invoice_pdf( $attachments, $email_id, $object ) {
  6. if ( 'customer_processing_order' === $email_id && is_a( $object, 'WC_Order' ) ) {
  7. $invoices = wc_gzdp_get_invoices_by_order( $object, 'invoice' );
  8. if ( empty( $invoices ) ) {
  9. // Generate invoices
  10. $args = apply_filters( 'woocommerce_gzdp_invoices_defaults', array( 'invoice_status' => wc_gzdp_get_default_invoice_status() ) );
  11. $invoice = wc_gzdp_get_invoice( false, 'invoice' );
  12. $invoice->refresh( $args, $object );
  13. $invoice->mark_as_sent();
  14. }
  15. $invoices = wc_gzdp_get_invoices_by_order( $object, 'invoice' );
  16. foreach( $invoices as $invoice ) {
  17. $attachments[] = $invoice->get_pdf_path();
  18. }
  19. }
  20. return $attachments;
  21. }
Add Comment
Please, Sign In to add comment