Support » Plugin: WooCommerce PDF Invoices & Packing Slips » export invoice number of subscriptions

  • celestapp



    I’m exporting my orders and extract the field stored in _wcpdf_invoice_number. I’m selling subscriptions and while the renewal orders do get an invoice number (visible when I click on the pdf file) this number is not exported by the field: _wcpdf_invoice_number. How can I export the invoice number of renewal orders of subscriptions?

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support alexmigf


    Hello @celestapp

    What plugin are you using for the subscriptions? Let me know.

    I’m using Woocommerce subscriptions.

    You can also see it in orders:

    The arrow on the left side shows that there is no invoice number visible for a renewal order. When clicking on the pdf file of the invoice (right arrow) there does appear an invoice number. So the numbering of the invoices is fine.

    The orders where there are no invoice number visible in the order page can not be exported with the _wcpdf_invoice_number meta.

    Plugin Support alexmigf


    Hello @celestapp

    Did you attached the invoice to the renewal email also? Because it’s not the same email from the regular orders. You could do it under WooCommerce > PDF Invoices > Documents > Invoice > Attach to.

    No I did not. Is this necessary? Do customers need to receive an email with the PDF in order to be able to download the invoice number with _wcpdf_invoice_number? Because the PDF is always made and the number is there it’s only not exportable.

    If so, I did not send those mails and I adjusted the settings to send the renewal invoice. So I assume it will work in the future? However, is there a way in which I can extract the invoice numbers of renewal orders in the past?

    Plugin Support alexmigf


    Hello @celestapp

    Ok, don’t attach it then.

    Please try adding this to your theme functions.php file:

    add_action('woocommerce_subscriptions_switch_completed', 'wpo_wcpdf_create_invoice_number');
    function wpo_wcpdf_create_invoice_number ( $order ) {
    	$order = wc_get_order( $order->get_id() );
    	$invoice = wcpdf_get_document( 'invoice', $order, true );

    If you never worked with actions/filters please read this documentation page: How to use filters

    I don’t think it’s working. I added the code as a snippet to my website.

    Do I need any further settings within the pdf plugin and my email settings? It seems to be kind of random when an order gets an invoice number in general:

    At this moment I have the PDF invoice attach settings set to:
    – new order processed
    – order completed
    – customer renewal invoice
    – new order (admin)

    I’m only sending emails for a new order being processed.

    However I assume that with the code you placed above it should be possible to create the invoice number based on ‘switching a subscription’? Is there any code that I could use to get the invoice number of all orders with a status of being processed or completed? Renewal or not?

    Plugin Support alexmigf


    Hello @celestapp

    Could you please remove the script i gave to you and attach the document to the ‘Renewal Processing’ email? Also check under WooCommerce > Settings if you didn’t disable this email.

    Just for you to know, this will not create invoices to existing renewal orders, only for new orders.

    • This reply was modified 1 week, 2 days ago by alexmigf.

    So you have to send an email with the invoice? I really don’t want to do that since my customers will then constantly be reminded about the costs of the subscription.

    Isn’t there any other way to export the invoice numbers?

    Plugin Author Ewout


    To export invoice numbers, those invoices will need to have been created first.
    There are 3 options to do that:

    • Automatically by means of email attachment (which I understand you don’t want)
    • Manually via the admin (either in bulk or on a per-order basis) by clicking the PDF icon – this will then generate the invoice
    • Programmatically at specific order status changes (via the above code snippet)

    The email attachment and code snippet actions will only work for new orders, for old orders you need to manaully create the invoices to be able to export them.

    One change you will probably want to make to the code if you go for the programmatic option, is to replace woocommerce_subscriptions_switch_completed by woocommerce_renewal_order_payment_complete:

    add_action('woocommerce_renewal_order_payment_complete', 'wpo_wcpdf_create_invoice_number');
    function wpo_wcpdf_create_invoice_number ( $order_id ) {
    	$invoice = wcpdf_get_document( 'invoice', $order_id, true );
    • This reply was modified 1 week, 1 day ago by Ewout. Reason: better action hook for renewal orders
Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.