Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'woocommerce_email_attachments', 'my_child_attach_invoice_pdf', 10, 3 );
- function my_child_attach_invoice_pdf( $attachments, $email_id, $object ) {
- if ( 'customer_processing_order' === $email_id && is_a( $object, 'WC_Order' ) ) {
- $invoices = wc_gzdp_get_invoices_by_order( $object, 'invoice' );
- if ( empty( $invoices ) ) {
- // Generate invoices
- $args = apply_filters( 'woocommerce_gzdp_invoices_defaults', array( 'invoice_status' => wc_gzdp_get_default_invoice_status() ) );
- $invoice = wc_gzdp_get_invoice( false, 'invoice' );
- $invoice->refresh( $args, $object );
- $invoice->mark_as_sent();
- }
- $invoices = wc_gzdp_get_invoices_by_order( $object, 'invoice' );
- foreach( $invoices as $invoice ) {
- $attachments[] = $invoice->get_pdf_path();
- }
- }
- return $attachments;
- }
Add Comment
Please, Sign In to add comment