Invoice number
-
Hey there!
Thanks for your work and for the plugin. It seems to work great, easy installation as well.We have following problem: In Germany, invoice numbers must be consecutive, there must be no gaps. The plugin uses the order number, which unfortunately does not correspond to this principle in WooCommerce.
Are there plans to integrate separate invoice numbers? A simple integration would be conceivable in the following way, for example (still to be extended, e.g. with a separate number format or similar).// Add a sequential invoice number to the order
add_action( 'woocommerce_checkout_update_order_meta', 'add_sequential_invoice_number' );
function add_sequential_invoice_number( $order_id ) {
// Retrieve the current invoice number, increment it by 1
$invoice_number = get_option( 'woocommerce_invoice_number', 0 ) + 1;
// Update the order meta with the new invoice number
update_post_meta( $order_id, '_invoice_number', $invoice_number );
// Update the stored option for the next invoice number
update_option( 'woocommerce_invoice_number', $invoice_number );
}
// Display the invoice number in the admin order details
add_action( 'woocommerce_admin_order_data_after_order_details', 'display_invoice_number_in_admin_order_meta' );
function display_invoice_number_in_admin_order_meta( $order ) {
// Retrieve the invoice number from the order meta
$invoice_number = get_post_meta( $order->get_id(), '_invoice_number', true );
// Display the invoice number if it exists
if ( $invoice_number ) {
echo '<p><strong>Invoice Number:</strong> ' . esc_html( $invoice_number ) . '</p>';
}
}
// Add "Invoice Number" column to the orders overview
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'add_invoice_number_column_to_orders' );
function add_invoice_number_column_to_orders( $columns ) {
$reordered_columns = array();
// Insert the "Invoice Number" column after the "Status" column
foreach ( $columns as $key => $column ) {
$reordered_columns[$key] = $column;
if ( $key === 'order_status' ) {
$reordered_columns['invoice_number'] = __( 'Invoice Number', 'theme_domain' );
}
}
return $reordered_columns;
}
// Display content of the invoice number column
add_action( 'manage_woocommerce_page_wc-orders_custom_column', 'display_invoice_number_column_content', 10, 2 );
function display_invoice_number_column_content( $column, $order ) {
// Check if the current column is "invoice_number"
if ( 'invoice_number' === $column ) {
// Retrieve the invoice number from the order meta
$invoice_number = get_post_meta( $order->get_id(), '_invoice_number', true );
// Display the invoice number or a dash if it's empty
if ( ! empty( $invoice_number ) ) {
echo esc_html( $invoice_number );
} else {
echo '-';
}
}
}
- You must be logged in to reply to this topic.