• Resolved posetiveone

    (@posetiveone)


    HI,I just installed in this plugin after moving from another. So far i like it better. My query is that i have about 700 invoices created with old plugin, now when i reprint an old invoice for a customer or they log in to print it it generates the next available inv no while maintaining the old order number .

    Example, I have a May order that was order no 6920 and inv 10487
    When i go to print now it is now order no. 6920 and Inv 10702

    Any ideas, i started your plugin with the next available from the old plugin prior to deactivating it.
    I searched the forum but couldn’t match a result with my query.

    Much appreciated

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @posetiveone

    Is the old invoices numeration sequential and without holes?

    Plugin Contributor Ewout

    (@pomegranate)

    If you can let us know what plugin you were using prior to ours, we may be able to provide a code snippet that uses the old plugins invoice number if it exists, and otherwise generate a new invoice number.

    Thread Starter posetiveone

    (@posetiveone)

    Great, it was by Tyche software.

    Print Invoice & Delivery Notes for WooCommerce

    https://en-au.www.ads-software.com/plugins/woocommerce-delivery-notes/

    Thank you very much, legendary service!

    Regards George

    Plugin Contributor Ewout

    (@pomegranate)

    Hi George!
    The most simple approach is to handle the scenario where the order has an invoice from that plugin and does not have an invoice from our plugin yet, this code snippet will then use the invoice number from the other plugin when generating the ‘new’ invoice:

    
    add_filter( 'wpo_wcpdf_external_invoice_number_enabled', '__return_true' );
    add_filter( 'wpo_wcpdf_external_invoice_number', function( $invoice_number, $document ){
    	return is_callable( array( $document->order, 'get_meta' ) ) ? $document->order->get_meta( '_wcdn_invoice_number' ) : null;
    }, 10, 2 );
    

    However, this will not automatically handle invoice dates. You have two options here: either set our plugin to use the order date as the invoice date or use another code snippet to override the invoice date based on the date that the Tyche plugin stored:

    
    add_action( 'wpo_wcpdf_invoice_get_date', function( $date, $document ) {
    	if ($document->get_type() == 'invoice' && is_callable( array( $document->order, 'get_meta' ) ) ) {
    		if( $wcdn_date = $document->order->get_meta( '_wcdn_invoice_date' ) ) {
    			$date = new WC_DateTime( "@{$wcdn_date}", new DateTimeZone( 'UTC' ) );
    		}
    	}
    	return $date;
    }, 10, 2 );
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Note that this will not change invoices already generated with our plugin!

    Thread Starter posetiveone

    (@posetiveone)

    Wow, I can thank you enough, although I am embarrassed to say I am not sure where and how to apply the code. I am ok mostly with navigating my site and finding things but lack the knowledge to do this, however i will read the guide on filters.

    As for the date, I am happy to use the order date as the invoice date, If I do this with your plugin, will all the old invoices still pick up the old date.

    I think its amazing what you guys do with code.

    Thank you in advance.

    George

    Plugin Contributor Ewout

    (@pomegranate)

    As for the date, I am happy to use the order date as the invoice date, If I do this with your plugin, will all the old invoices still pick up the old date.

    If you set the invoice date to use the order date under Documents > Invoice, our plugin will use the date that WooCommerce already has recorded for the order, so if I understand your question correctly, the answer is yes!

    I understand that working with code may sound a little scary, but if you use the Code Snippet plugin from our guide on using filters, you’ll find that it’s not much more than copy paste. Unfortunately for specific situations like this, code snippets are the best way to solve this (without bloating our plugin). You could even enable it temporarily, then download all the invoices from the old orders via our plugin (which will then migrate the data from the old plugin) and then deactivate the code when you’re done.

    Let us know if you need more help with any of this!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Migrate other plugin inv no.’ is closed to new replies.