Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Invoice number format ignored (v5.1)

  • Resolved kontur



    I am wondering why the invoice number formatting is not working in v 5.1 both in the Simple template and in my custom template.

    My admin settings:

    Next invoice number: 14
    Number format
    Prefix: OT[invoice_year]
    Fill: 6

    On the invoice I am seeing simply “14”. When hooking in to wpo_wcpdf_raw_document_number and dumping the number and settings I get:

    array(7) { ["number"]=> int(13) ["formatted_number"]=> string(2) "13" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["document_type"]=> string(7) "invoice" ["order_id"]=> int(883) ["padding"]=> string(0) "" } array(3) { ["prefix"]=> string(16) "OT[invoice_year]" ["suffix"]=> string(0) "" ["padding"]=> string(1) "6" }

    It appears the settings are correctly read from the settings, but the output still is a simple number.


Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Ewout


    Hello Johannes,
    I can’t reproduce the issue and we haven’t had any other reports about this. You mention hooking into wpo_wcpdf_raw_document_number, are you using any other hooks that might affect the invoice number? The dump that you made is actually two arrays, the first matches the output (no prefix, no padding), is it possible that one is the number data from that particular order and the other the latest settings?

    array(7) {
    	["number"]=> int(13)
    	["formatted_number"]=> string(2) "13"
    	["prefix"]=> string(0) ""
    	["suffix"]=> string(0) ""
    	["document_type"]=> string(7) "invoice"
    	["order_id"]=> int(883)
    	["padding"]=> string(0) ""
    array(3) {
    	["prefix"]=> string(16) "OT[invoice_year]"
    	["suffix"]=> string(0) ""
    	["padding"]=> string(1) "6"

    Note that these settings never affect existing documents/invoice number!


    dumping the number and settings

    So I am dumping the first two arguments the hook receives.

    I don’t believe there are any other hooks. The site does not use any caching atm either.

    Unfortunately I cannot show you online since the website is WIP and confidential.

    I do have the “Always use most current settings” checked, too.


    Generated invoice: (Custom template) and (Simple template).

    WP v 5.1
    Plugin v 2.2.9

    Let me know if you want me to try output or debug anything in particular.

    Plugin Author Ewout


    This appears to be an old invoice though (dated march 5th), and “Always use most current settings” does not affect the invoice number. Have you tested new invoices too?
    As you can see here, the settings (second argument from that filter) are only used if they are not stored in the number data already (first argument).

    If you want to apply the new formatting settings to an existing invoice, you can click the edit button for the invoice data in the order backend, then save the order without making changes. This will keep the number and date in tact, and apply the new settings.

    Alternatively you could use that wpo_wcpdf_raw_document_number hook you already mentioned to fake a ‘new number’ scenario:

    add_action('wpo_wcpdf_raw_document_number', 'wpo_wcpdf_use_latest_number_settings', 10, 4 );
    public function wpo_wcpdf_use_latest_number_settings( $number, $settings, $document, $order ) {
    	if (is_array($number)) {
    		$number = $number['number'];
    	return $number;
    • This reply was modified 4 months, 1 week ago by  Ewout. Reason: added alternatives

    Okay, that explains it!

    I yesterday worked on tweaking the custom template just refreshing on existing invoices and only the last thing I tried was to adjust the number; without effect. Now creating a new one renders the number correctly.

    Thanks for this great plugin and your help 🙂

    Plugin Author Ewout


    Our posts crossed – I added some extra tips above!

    Thanks also for that. I saw that hook but did not want to go implementing any custom logic so I don’t have to worry about changes in updates that might require more action. Thanks for pointing it out also! Left the plugin a review :thumbsup:

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.