• I’m trying to send pdf invoices as attachments to customers using the method wp_mail(). The method will look something like this:

    $attachments = array(WP_CONTENT_DIR .'/uploads/2019/08/your-pdf-fine-name.pdf');
    $to          = [email protected];
    $subject     = "PDF in wp_mail";
    $message     = "Please check the attached PDF.";
    $headers     = 'From: [email protected]' . "\r\n";
    wp_mail( $to, $subject, $message, $headers, $attachments);

    The attachment variable should be equal to the location of the PDF invoice. How do I get the location of an already generated PDF invoice using an order id?

    Thanks in advance.

    • This topic was modified 3 years, 3 months ago by waffeltje.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @waffeltje

    Using the free version of the plugin the files are store in a temporary folder, see here.

    Thread Starter waffeltje

    (@waffeltje)

    Hi Alex,
    Thanks for the reply.

    I now have the following bit of code:

      $order_id = 6107; 
      $invoice = wcpdf_get_document( 'invoice', $order_id );
      $filename = $invoice->get_filename();
      $tmp_path = WPO_WCPDF()->main->get_tmp_path( 'attachments' );
      $pdf_path = $tmp_path . $filename;
      $attachments = array($pdf_path );
      $message = "Path: ".$pdf_path .".";
      $headers = array('Content-Type: text/html; charset=UTF-8');
      $headers[] = 'From: Test Sender <[email protected]>';
      $headers[] = 'Content-Type: text/html';
      $headers[] = 'charset=UTF-8';
      wp_mail('[email protected]', 'Attachment test', $message, $headers, $attachments);   

    The email doesn’t contain the pdf invoice yet. When I check the folder in which the PDF should be located it is empty. Probably because of the temporary nature of the folder. Do you know how I can generate the PDF on te fly and attach it to the email?

    Thanks in advance.

    • This reply was modified 3 years, 3 months ago by waffeltje.
    Plugin Contributor kluver

    (@kluver)

    Hi @waffeltje,

    You should be able to generate the PDF like this:

    if ( $order = wc_get_order( $order_id ) ) {
        $invoice = wcpdf_get_invoice( $order, true );
        $pdf = $invoice->get_pdf();
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Invoice location’ is closed to new replies.