• Resolved anorakgirl

    (@anorakgirl)


    Hi,
    I am writing some code which emails a CSV of all pending orders to the company which fulfills orders for the shop. I would also like to attach pdf packing notes for all the orders to the email. Is it possible to hook into the code somehow to generate a file to use as an attachment?
    Thanks!

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

    (@pomegranate)

    Hi!
    Yes you can. Here’s an example code snippet that creates and saves the PDF file:

    
    <?php
    global $wpo_wcpdf;
    $template_type = 'invoice'; // or: 'packing-slip', 'proforma', 'credit-note';
    // create PDF - make sure you have your $order_id.
    $pdf = $wpo_wcpdf->export->get_pdf( $template_type, (array) $order_id );
    
    // get temp path
    $tmp_path = $wpo_wcpdf->export->tmp_path('attachments');
    
    // save file
    $pdf_filename = $wpo_wcpdf->export->build_filename( $template_type, (array) $order_id, 'download' );
    $pdf_path = $tmp_path . $pdf_filename;
    file_put_contents ( $pdf_path, $pdf );
    ?>
    

    Hope that helps!
    Ewout

    • This reply was modified 8 years, 1 month ago by Ewout.
    Thread Starter anorakgirl

    (@anorakgirl)

    Thanks! this worked really well.

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome. Happy coding/selling!

    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘create pdf from code’ is closed to new replies.