• Resolved anirudh5bs

    (@anirudh5bs)


    Hello
    We were using some other plugin before, but now that we start using your plugin, everything seems working fine. However, there are 21k+ orders, since the invoice number is already set by previous plugin for these 21k orders, how do we migrate all those invoice numbers for old orders? regenerating for 21k orders takes way too long. Is there any solution?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    We can certainly help with that. Which plugin were you using before ours? Do you know the meta key it used for the invoice number? You may be able to find it using Store Toolkit (see: Finding WooCommerce Custom Fields)

    Let us know and we’ll do our best to help!

    Thread Starter anirudh5bs

    (@anirudh5bs)

    Hello

    We had purchased this plugin: https://www.webtoffee.com/product/woocommerce-pdf-invoices-packing-slips/

    1. Primary reason is it generates pick slips. On the order list page when we select multiple orders and under bulk action, we can create pick slips. It’s a list of all products from the selected orders. Our client has a warehouse and they generate pick slips of received orders and send that list to the warehouse to pick up those items. Your plugin doesn’t support this. (packing slip and picklist are different)

    2. Your plugin has only Invoice and Packing slip, we need more options. This is also one of the reasons we went with them.

    3. Since we are not getting proper support and the invoice is not showing correct numbers. We decided to go with yours but as I said, generating pick slips is our priority. Since we are coming to your plugin, we need to migrate the old orders’ invoice number as it is to the new invoice.

    Plugin Contributor Ewout

    (@pomegranate)

    Thanks, that helps! Checking the free version of their plugin, it appears they are storing the invoice number under the meta key wf_invoice_number in the order meta, and the invoice date is stored (as a timestamp) under _wf_invoice_date.

    Here’s a code snippet that will automatically use those legacy invoice numbers and dates for invoices that are requested for older orders:

    add_filter( 'wpo_wcpdf_invoice_get_date', function( $date, $document ) {
    	if ( $document->get_type() == 'invoice' && $order = $document->order ) {
    		if ( $legacy_date = $order->get_meta('_wf_invoice_date') ) {
    			$date = new \WC_DateTime( "@{$legacy_date}", new \DateTimeZone( 'UTC' ) );
    			$document->set_date( $date );
    		}
    	}
    	return $date;
    }, 10, 2 );
    
    add_filter( 'wpo_wcpdf_invoice_get_number', function( $number, $document ) {
    	if ( $document->get_type() == 'invoice' && $order = $document->order ) {
    		if ( $legacy_number = $order->get_meta('wf_invoice_number') ) {
    			$document->set_number( $legacy_number );
    			$number = $document->get_number( '', null, 'edit' );
    		}
    	}
    	return $number;
    }, 10, 2 );

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

    Thread Starter anirudh5bs

    (@anirudh5bs)

    We found an issue. We configured it on the client site. 1715 is the next invoice number https://prnt.sc/E7bzfYXPQLRW if the client opens some other old order and clicks on the invoice, it generates a new invoice number 1715 (it won’t show it on the invoice as it is customized) but when new customer order, they get invoice number 1716, this is not maintaining sequential for the new invoice. We should make it stop generating new invoice numbers for old orders. How to do that?

    • This reply was modified 2 years, 7 months ago by anirudh5bs.
    Plugin Contributor Ewout

    (@pomegranate)

    I see – I didn’t realize it would still generate the numbers even though it would show the old ones. Here’s an improved version of the custom code that will prevent that from happening, please replace the previous code with this:

    add_filter( 'wpo_wcpdf_invoice_get_date', function( $date, $document ) {
    	if ( $document->get_type() == 'invoice' && $order = $document->order ) {
    		if ( $legacy_date = $order->get_meta('_wf_invoice_date') ) {
    			$date = new \WC_DateTime( "@{$legacy_date}", new \DateTimeZone( 'UTC' ) );
    			$document->set_date( $date );
    		}
    	}
    	return $date;
    }, 10, 2 );
    
    add_filter( 'wpo_wcpdf_external_invoice_number_enabled', '__return_true' );
    add_filter( 'wpo_wcpdf_external_invoice_number', function( $number, $document ) {
    	if ( ! empty( $document->order ) ) {
    		$number = $document->order->get_meta( 'wf_invoice_number' ); // if $number is empty, the plugin will generate a new number
    	}
    	return $number;
    }, 10, 2 );
    Thread Starter anirudh5bs

    (@anirudh5bs)

    again, i went to old order it was like this https://prnt.sc/gi24HJ5GGsy7 and clicked on pdf invoice https://prnt.sc/hzvOx2NBWcZO it became like this, again new invoice number is generated for old order. is it possible to make only when when meta wf_invoice_number is empty, generate new order number or else fetch meta inv number, because meta wf_invoice_number is just numbers. is it possible?

    Plugin Contributor Ewout

    (@pomegranate)

    that’s very strange, I tested and confirmed the issue you were experiencing and then with the new snippet the issue was resolved. Are you sure you removed all of the old code?

    Thread Starter anirudh5bs

    (@anirudh5bs)

    sorry mu bad, everything working fine. Thank You.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Migrate Invoice number’ is closed to new replies.