Add Custom Fields (e.g. VAT) to Invoices

Add Fields to Billing Information #

For fields to be added to invoices, they need to be added to billing. To do this, go to B2BKing -> Registration Fields, click on the field(s) you need, and enable the 'Add custom field to billing' checkbox.

'Add custom field to billing' checkbox

Example

We have created 2 B2BKing custom fields and enabled the "add custom field to billing". The fields are: "new test field" and "VAT Number". We can see these fields on the checkout page as billing fields:

Add Fields to Invoices #

If fields have been added to billing, most invoice plugins will automatically display them on their invoices.

We recommend you use the WooCommerce PDF Invoices & Packing Slips by WP Overnight plugin. The free version is sufficient.

We place an order and we see the fields in our previous screenshots have been added to the PDF invoice:

If you would like to do custom work and display fields in a more specific or unique manner, there are multiple ways you can add custom fields:

  • use one of the plugin's Premium extensions
  • directly modify the template of the invoice
  • use one of the plugin's action hooks

Here you can read more about invoice customization options with this invoice plugin.

Here you can find a list of plugin hooks for the invoice plugin.

Note: Generally, other invoice plugins should work as well, although the plugin we recommend above is the most popular option.

"Germanized" Plugin Invoices #

If your shop uses Germanized for invoice generation, by default their plugin will not include custom B2BKing fields - such fields have to be added through a code snippet.

To add the VAT number to Germanized invoices, add the following PHP code snippet to your site:

add_filter('storeabill_invoice_get_formatted_address', function($address, $document){
    $order_id = $document->get_order_id();
    $order = wc_get_order($order_id);
    if ($order){
        $vat_number = $order->get_meta('vat_number');
        $address .= '<br>'.$vat_number;
    }

    return $address;
}, 10, 2);

To add other fields, replace $order->get_meta('vat_number'); with $order->get_meta('b2bking_custom_field_1234'); where 1234 is the field ID of your custom field. The field ID of a field can be seen in the URL when you edit that field in the backend (e.g. if you see ?post=456 in the URL, then 456 is the ID).

This should add the VAT number or custom field here after the billing address:

9813540054.png

Powered by BetterDocs