invoice pdf does not show custom fields
-
Custom fields created with flexible checkout fields plugin show up on the invoice pdf that is send to the customer BUT not on the one send to the backend admin. Also when downloading the pdf with from the wordpress backend they are missing.
Any ideas on how to resolve / troubleshoot this?
-
Thanks for the details!
It’s possible that the issue is related to how the custom field data is being read by the invoicing plugin.
Could you please double-check whether the meta names (field IDs) used by the Flexible Checkout Fields plugin are the same ones that the invoicing plugin expects when generating PDFs?
Sometimes, fields may show correctly in one context (like the customer email) but not in another (like the admin copy), especially if the field names aren’t matched consistently.You can also inspect the order meta in the backend (under “Custom Fields” for the order) to verify if the values are saved correctly and under the expected keys.
Let us know what you find — we’ll be happy to assist further from there!
Hi,
still trying to figure this out – is flexible checkout field plugin sending any custom fields directly to shipping adresses or something?
Without any shipping manipulation from the invoice generating plugin (it’s German Market by the way) the custom fields are printed on the PDF send to the customer but they are not available on the backend admins PDF. According to German Market Developer they are using the same function for generating both PDFs, so it’s maybe a timing when you insert the additional fields to the shipping address?
Any hints or details on how to troubleshoot this are appreciated.Could you please report this problem through our official support channel?
I would like to consult this issue with our developer, and it would be helpful to have a view of the order panel and a screenshot of the invoice with the added fields. It’s better not to share those details here.Can you report via this form? You can use Pre-sale Question option.
Thank you
This problem can be resolved by adding two filters to functions.php file.
The first filter will allow data to be passed between the Flexible Checkout Fields plugin and the invoice generation plugin used in the shop.
function add_custom_field_to_address_formats( $formats ) {
foreach ( $formats as $country_code => $format ) {
// Add the custom field placeholder to the end of each format
$formats[ $country_code ] = $format . "\n{custom_field}";
}
return $formats;
}
add_filter( 'woocommerce_localisation_address_formats', 'add_custom_field_to_address_formats', 10, 1 );You have to add a placeholder from the Flexible Checkout Fields plugin for each or selected country… the placeholder will be the meta name without the “_billing”, i.e., from the image it will simply be “{test}”.
And the second one, resolving formatting issues. To resolve the formatting issue, you need to define this precisely by editing the string e.g. “{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}” and adding the appropriate placeholders and newline characters there “\n”
// this is just to show what placeholders are available, and is not needed when second filter will be used
add_filter( 'woocommerce_formatted_address_replacements', function( $placeholders, $args ) {
print '<pre>';
print_r( $placeholders );
print '</pre>';
return $placeholders;
}, 10, 2 );
// this is the only filter needed - but needs to be adjusted
add_filter( 'woocommerce_localisation_address_formats', function( $formats ) {
foreach ( $formats as $country_code => $format ) {
// here we add custom field at the end of each format
// $formats[ $country_code ] = $format . "\n{custom_field}";
// but (alternatively) we can define full format for each country - see available placeholder by running the code above
$formats[ $country_code ] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}\n{custom_field}";
}
return $formats;
}, 10, 1 );Hi,
I need to revisit this issue – the above approach works for the address formatting shown on the pdf that’s downloadable from the backend and that is send to the backend admin.
The address format in the invoice pdf that is send to customer is NOT affected by this code sniplet.
The effect to the delivery pdf is also unexpected and wrong – the custom field is not shown, but {custom_field} as filled in in the code above:Firmenname
{firmen_abteilung}
vorname nachnahme
Strasse
Appartment
Stadt 10243Please advice,
Thanks a lot,
Stefan
The topic ‘invoice pdf does not show custom fields’ is closed to new replies.