Support » Plugin: WooCommerce PDF Invoices » How can I attach a PDF invoice to my custom email template?

  • Resolved arnisraido

    (@arnisraido)


    Hi!

    When I set order status to Complete, a customer receives an Email with my custom template. I don’t need to attach a PDF invoice to this mail because a customer has been received this invoice in the previous state.

    But I need to send a PDF invoice to mail, e.g. packagers@example.com.

    – I can do this by:

    ~~~php
    add_action( ‘woocommerce_order_status_completed’, ‘order_complete_send_to_packaging’, 1);
    function order_complete_send_to_packaging($order_id) {

    global $woocommerce;
    //Instantiate mailer
    $order = new WC_Order($order_id);
    $mailer = $woocommerce->mailer();

    $subject = “Mail subject”;

    // Buffer
    ob_start();

    // Get mail template
    woocommerce_get_template(‘pdf/myCustom/invoice.php’, array(
    ‘order’ => $order
    ));
    // Get contents
    $message = ob_get_clean();
    // Send the mail
    woocommerce_mail(“packagers@example.com”, $subject, $message, $headers = “Content-Type: text/htmlrn”, $attachments = “”);
    }
    ~~~

    But how can I attach a PDF invoice to my custom email template?

Viewing 1 replies (of 1 total)
  • Plugin Author Bas Elbers

    (@baaaaas)

    Something like below should work.

    
    $invoice = new BEWPI_Invoice( $order->get_id() ); // use $order->id when using older WC version.
    $invoice_path = $invoice->get_full_path();
    $attachments[] = $invoice_path;
    
Viewing 1 replies (of 1 total)
  • The topic ‘How can I attach a PDF invoice to my custom email template?’ is closed to new replies.