Thank you very much for your time, now I know the error was in the shipping_address, based on that I made the following modifications.
Now it works on invoice and packing-slip. Thank you very much
add_action ('wpo_wcpdf_after_shipping_address', function ($template_type, $order) {
if ($template_type == 'packing-slip') {
$invoice = wcpdf_get_document ('packing-slip', $order);
// if cnpj exists, show it
if ( !empty($invoice-> get_custom_field ('billing_cnpj') ) ) {
echo '<br>CNPJ:' . $invoice-> get_custom_field ('billing_cnpj');
// otherwise, show the cpf
} else {
echo '<br>CPF: '. $invoice-> get_custom_field ('billing_cpf');
}
}
}, 10, 2);
and
add_action ('wpo_wcpdf_after_billing_address', function ($template_type, $order) {
if ($template_type == 'invoice') {
$invoice = wcpdf_get_document ('invoice', $order);
// if cnpj exists, show it
if ( !empty($invoice-> get_custom_field ('billing_cnpj') ) ) {
echo '<br>CNPJ:' . $invoice-> get_custom_field ('billing_cnpj');
// otherwise, show the cpf
} else {
echo '<br>CPF: '. $invoice-> get_custom_field ('billing_cpf');
}
}
}, 10, 2);
i′m using code snippet plugin.