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