• Hi!

    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 Contributor alexmigf

    (@alexmigf)

    Hello @celestapp

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

    Thread Starter celestapp

    (@celestapp)

    I’m using Woocommerce subscriptions.

    Thread Starter celestapp

    (@celestapp)

    You can also see it in orders:
    https://www.weeklyflower.nl/wp-content/uploads/2020/06/invoice-number.jpg

    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 Contributor alexmigf

    (@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.

    Thread Starter celestapp

    (@celestapp)

    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 Contributor alexmigf

    (@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

    Thread Starter celestapp

    (@celestapp)

    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:
    https://www.weeklyflower.nl/invoice-number-2/
    https://www.weeklyflower.nl/invoice-number-3/
    https://www.weeklyflower.nl/invoice-number-4/
    https://www.weeklyflower.nl/invoice-number-5/

    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 Contributor alexmigf

    (@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 4 years, 8 months ago by alexmigf.
    Thread Starter celestapp

    (@celestapp)

    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 Contributor Ewout

    (@pomegranate)

    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 4 years, 8 months ago by Ewout. Reason: better action hook for renewal orders
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘export invoice number of subscriptions’ is closed to new replies.