Hi @brnveebilahendused,
Indeed, removing the temporary files or resetting the ‘next invoice number’ will not affect invoices that you have already created. This is data that is stored in the database, per order.
Now there are two ways to do this, a simple/fool-proof method and an advanced, more dangerous method.
1) Simple method
If this is not for hundreds of orders, you can remove the invoice numbers (and dates manually) by opening the order in the WooCommerce backend, clicking the edit button in the “PDF Invoice Data” section and remove the number and date. Then save the order and it’s reset. Rinse and repeat.
2) Advanced method
This is more difficult and also more dangerous because you’re going to directly modify the database with a script. Here’s the script:
add_action( 'init', 'wpo_wcpdf_remove_invoice_numbers');
function wpo_wcpdf_remove_invoice_numbers() {
if ( isset( $_GET['wcpdf_remove_invoice_numbers'] ) ) {
$args = array(
//'status' => array('processing','completed'),
'return' => 'ids',
'type' => 'shop_order',
'limit' => -1,
//'date_created' => '2017-03-22...2017-11-22',
);
$order_ids = wc_get_orders( $args );
foreach ($order_ids as $order_id) {
$order = wc_get_order( $order_id );
$order->delete_meta_data( '_wcpdf_invoice_number' );
$order->delete_meta_data( '_wcpdf_invoice_number_data' );
$order->delete_meta_data( '_wcpdf_invoice_exists' );
$order->delete_meta_data( '_wcpdf_formatted_invoice_number' );
$order->save();
}
wp_die(sprintf('Invoice numbers removed from %s orders!', count($order_ids)));
}
}
Instructions:
- Install the script on your site (read this if you haven’t worked with actions/filters before!)
- Open a url on your site and add ‘wcpdf_remove_invoice_numbers=true’ to it. For example yoursite.com/wp-admin/edit.php?post_type=shop_order&wcpdf_remove_invoice_numbers=true
- You should see a page “Invoice numbers removed from ### orders!” (may take some time to load if you have many orders in your shop).
- REMOVE the script, to prevent other people from executing it
- You can then create the invoices again (either in bulk or per order).
additional tweaks:
- If you have many orders in your shop but only want to remove the order numbers for a specific date range, you can uncomment the
date_created
line in the code snippet and alter the date rande (format: YYYY-MM-DD). This also helps if there’s too many orders to process in one request
- Same for the order status.
I recommend making a site backup before doing this!
Hope that helps!
Ewout