Title: Manually generate PDF invoice with function
Last modified: October 4, 2017

---

# Manually generate PDF invoice with function

 *  Resolved [specex](https://wordpress.org/support/users/specex/)
 * (@specex)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/)
 * I have a WP-Lister Pro for Amazon installed, when the order is completed it won’t
   auto generate the PDF invoice. For other standard Woocommerce’s order is working
   good and pdf is generated.
 * Can you suggest how i can trigger the pdf once it has been completed by custom
   function or hook? Thanks

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Contributor [kluver](https://wordpress.org/support/users/kluver/)
 * (@kluver)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9558692)
 * Hi Specex,
 * Yes this is possible. Please add the following to your functions.php:
 *     ```
       add_action('woocommerce_order_status_completed', 'wpo_wcpdf_create_invoice_number');
       function wpo_wcpdf_create_invoice_number ( $order_id ) {
       	$order = wc_get_order( $order_id );
       	$invoice = wcpdf_get_document( 'invoice', $order, true );
       }
       ```
   
 * If you have never worked with code snippets or functions.php pleas read this 
   first: [How to use filters](https://docs.wpovernight.com/general/how-to-use-filters/)
 * I hope this answers your question!
 * With kind regards,
 * Michael
 *  Thread Starter [specex](https://wordpress.org/support/users/specex/)
 * (@specex)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9561093)
 * Thanks for quick reply.
 * The above code trigger a blank screen after i click the Complete order button.
   After refresh the order page again the order went to completed but no PDF generated.
   Perhaps is caused by old version plugin?
 * I’m using
    WooCommerce PDF Invoices & Packing Slips 1.5.37 WooCommerce PDF Invoices&
   Packing Slips Professional 1.4.2 Woocommerce 2.6.4
 * Thanks in advance
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9561269)
 * Hi! That code is for WooCommerce PDF Invoices & Packing Slips 2.0 or higher, 
   so that explains why this didn’t work for you. Unfortunately we do not have such
   a function for 1.5.
 *  [psysolix](https://wordpress.org/support/users/psysolix/)
 * (@psysolix)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9677843)
 * Hi there!
 * Sorry to open this thread again. I was wondering, how I use the Class object 
   returned from **wcpdf_get_document**.
 * In my case, I need to trigger the PDF generation if my conditional is met. So
   if vat number is filled in in Checkout, I want to add the PDF attachment to the
   customer order mail.
 * The steps where I need some help are in the code comments below. Could you please
   help me on this?
 * Anyhow, loving the plugin tho 🙂
 *     ```
       function xyz_checkout_fields_validation($order_id){
       	if(isset($_POST['vat_number'])){
       		$order = wc_get_order( $order_id );
       		$invoice = wcpdf_get_document( 'invoice', $order, true );
                       // $pdf = generatePDF($invoice)
                       // add $pdf as attachment
       	}
       }
       ```
   
 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9680659)
 * Hi! This function is just for generating the PDF, to handle attachments you need
   to approach it differently, as you can’t shoot the file out into the wild to 
   attach it to an email 🙂
 * The easiest way to do this is to enable the PDF attachment in the settings and
   then use the `wpo_wcpdf_custom_attachment_condition` filter to disable it for
   orders that don’t have a vat number (note that you have to query the order for
   this as the email will not always be sent out at the same time the checkout is
   processed).
    This thread should get you started: [https://wordpress.org/support/topic/choose-whether-to-send-the-invoice/](https://wordpress.org/support/topic/choose-whether-to-send-the-invoice/)
 * Hope that helps!
    Ewout
 *  [psysolix](https://wordpress.org/support/users/psysolix/)
 * (@psysolix)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9681017)
 * Awesome! I will try this out 🙂
 * Thanks for the quick and solid advice!
 * Greets

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Manually generate PDF invoice with function’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

 * 6 replies
 * 4 participants
 * Last reply from: [psysolix](https://wordpress.org/support/users/psysolix/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/manually-generate-pdf-invoice-with-function/#post-9681017)
 * Status: resolved