Error generating invoices
-
With the latest version 3.6.3 an error is occurring and invoices are not generated. Specifically, the error comes from this piece of code that is responsible for including the client’s NIF in the invoice:
add_filter( ‘wpo_wcpdf_billing_address’, ‘include_nif_in_invoice’ );
function include_nif_in_invoice( $address ){
global $wpo_wcpdf;
echo $address . ‘‘; $wpo_wcpdf->custom_field( ‘NIF’, ‘NIF: ‘ ); echo ”;
}Specifically, the line that generates the error is: $wpo_wcpdf->custom_field( ‘NIF’, ‘NIF: ‘ );
Is there an update for this code that works with version 3.6.3?
Thank you.
-
Hi @pozoalcon,
This issue is happening because in the last release, v3.6.3, we have deleted legacy code that we were maintaining for years. Currently, the global variable
$wpo_wcpdfno longer exists, that is why the error is generated.That said, I have updated your code snippet, so it is working again following our current standards:
/** * PDF Invoices & Packing Slips for WooCommerce: * Incluye el NIF en los documentos PDF (dentro de los datos de facturación) */ add_filter( 'wpo_wcpdf_billing_address', function( $address, $document ) { if ( ! empty( $document ) && is_callable( array( $document, 'get_custom_field' ) ) && ( $nif = $document->get_custom_field( 'NIF' ) ) ) { $address .= sprintf( '<p>NIF: %s</p>', $nif ); } return $address; }, 10, 2 );Let us know whether it worked or you need more tweaks 😉
Yes, it works perfectly now. Thank you very much for your quick and accurate response.
Thanks for confirming that it worked, @pozoalcon! 🎉
If you don’t mind and have the time, do you think you could leave us a review?
Thanks in advance and all the best with your store!
Sure, here it is — https://wordpress.org/support/topic/fast-and-effective-support-14/#new-post
Wow! Thanks you very much for your 5-star review, @pozoalcon!
You have made my day! ❤️
Have a nice start of the week! 🕺
Hi @yordansoares,
I think I am having the same issue, as it arised after upgrading to version 3.6.3. When generating an invoice I get the following error (some data has been anonymized):
Fatal error: Call to a member function custom_field() on null
/usr/home/example.com/web/wp-content/themes/storefront child/functions.php (34)0 /usr/home/example.com/web/wp-includes/class-wp-hook.php(312): incluir_nif_en_factura(‘ANONYMOUS…’)
1 /usr/home/example.com/web/wp-includes/plugin.php(205): WP_Hook->apply_filters(‘ANONYMOUS…’, Array)
2 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php(93): apply_filters(‘wpo_wcpdf_billi…’, ‘ANONYMOUS…’, Object(WPO\WC\PDF_Invoices\Documents\Invoice))
3 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document-methods.php(102): WPO\WC\PDF_Invoices\Documents\Order_Document_Methods->get_billing_address()
4 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple/invoice.php(42): WPO\WC\PDF_Invoices\Documents\Order_Document_Methods->billing_address()
5 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(976): include(‘/usr/home/example…’)
6 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(879): WPO\WC\PDF_Invoices\Documents\Order_Document->render_template(‘/usr/home/example…’, Array)
7 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(834): WPO\WC\PDF_Invoices\Documents\Order_Document->get_html()
8 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(901): WPO\WC\PDF_Invoices\Documents\Order_Document->get_pdf()
9 /usr/home/example.com/web/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/class-wcpdf-main.php(466): WPO\WC\PDF_Invoices\Documents\Order_Document->output_pdf(‘inline’)
10 /usr/home/example.com/web/wp-includes/class-wp-hook.php(310): WPO\WC\PDF_Invoices\Main->generate_pdf_ajax(”)
11 /usr/home/example.com/web/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(”, Array)
12 /usr/home/example.com/web/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
13 /usr/home/example.com/web/wp-admin/admin-ajax.php(188): do_action(‘wp_ajax_generat…’)
14 {main}
I am not a programmer and I can’t determine if your solution also applies in this case.
Many thanks in advance.
Fatal error: Call to a member function custom_field() on null, it’s the same error I had. In the function file you must have this code on line 34: $wpo_wcpdf->custom_field( ‘NIF’, ‘NIF: ‘ ); threw out “;
Replace the piece of code where this line of code appears with the one indicated by Yordan, and the error should disappear.Hi @miquelperello,
As @pozoalcon mentioned, your case seems to be caused by the same reason: you are using an outdated code that is calling our method through
$wpo_wcpdfwhich is no longer available since v3.6.3.That said, you could try to adapt your code, following the same structure of the code snippet I left above, or share your code snippet in a new topic (so we do not disturb @pozoalcon with mail notifications), and I will update your code as a courtesy 🙂
Hi, I possibly have the same issue, when we activate the plugin it brings the full site down. If you could help by letting me know where to start with debugging / logs / anything else that might help that would be appreciated.
The topic ‘Error generating invoices’ is closed to new replies.