I’m sorry, there’s a nesting issue here: one of the arguments used to format the invoice number is the order number, which calls this filter, which calls the function for formatting the invoice number etc. infinitely.
This is a bit more code but should do the trick:
add_filter( 'woocommerce_order_number', 'woocommerce_invoice_order_number', 99, 2);
function woocommerce_invoice_order_number( $order_number, $order ) {
global $wpo_wcpdf;
$invoice_number = get_post_meta( $order->id, '_wcpdf_invoice_number', true);
// get format settings
$template_settings = get_option('wpo_wcpdf_template_settings');
$formats['prefix'] = isset($template_settings['invoice_number_formatting_prefix'])?$template_settings['invoice_number_formatting_prefix']:'';
$formats['suffix'] = isset($template_settings['invoice_number_formatting_suffix'])?$template_settings['invoice_number_formatting_suffix']:'';
$formats['padding'] = isset($template_settings['invoice_number_formatting_padding'])?$template_settings['invoice_number_formatting_padding']:'';
// Replacements
$order_year = date_i18n( 'Y', strtotime( $order->order_date ) );
$order_month = date_i18n( 'm', strtotime( $order->order_date ) );
foreach ($formats as $key => $value) {
$value = str_replace('[order_year]', $order_year, $value);
$value = str_replace('[order_month]', $order_month, $value);
$formats[$key] = $value;
}
// Padding
if ( ctype_digit( (string)$formats['padding'] ) ) {
$invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number);
}
$formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ;
return $formatted_invoice_number;
}
Let me know if that helps!