Plugin Contributor
Ewout
(@pomegranate)
Hello Samuel,
You can find instructions for adding a custom text in our documentation here:
Print a custom text after the order details table
Combined with the snippet from the custom field docs, you should be able to get what you need: Displaying a custom field – in a custom template
If you’re not sure which field name to use (the label may be different from the actual field name / meta key), check this guide: Finding WooCommerce Custom Fields.
If you prefer a solution that doesn’t require custom coding, the Premium Templates extension lets you add a custom text with or without custom fields via the Customizer interface.
Hope that helps!
Ewout
Hi Ewout,
thanks for the links. I`ve tried it this way before. But I am stuck somewhere.
I used this code snippet:
add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_custom_text’, 10, 2 );
function wpo_wcpdf_custom_text ($template_type, $order) {
global $wpo_wcpdf;
if ($template_type == ‘invoice’) {
?>
<tr class=Hinweis:</th>
<td><?php $wpo_wcpdf->hinweis(‘hinweis’); ?></td>
</tr>
<?php
}
}
The custom fileds name is: hinweis
And it should only appear on the invoice.
thank you.
Samuel
Plugin Contributor
Ewout
(@pomegranate)
Looks like you made a few typos in the HTML part! Try this:
<tr class="hinweis">
<th>Hinweis:</th>
<td><?php $wpo_wcpdf->custom_field('hinweis'); ?></td>
</tr>
awesome it`s already displaying the label: Hinweis
Unfortunately I am not able to see the content (text) I filled in the text field.
Do I need any command like: get_custom_field?
I found the mistake. Everything works so far. Thank you!
I am trying to hide it now if there is no content in the custom field.
It would also be handy to have the custom field only by certain products.
—–
add_action( 'wpo_wcpdf_before_order_data', 'wpo_wcpdf_custom_text', 10, 2 );
function wpo_wcpdf_custom_text ($template_type, $order) {
global $wpo_wcpdf;
if ($template_type == 'invoice' )
$product = get_custom_field( $product->id, '_wcpdf_custom_text', true );
{
echo '<h4>' . __( 'Hinweis:' ) . ' (' . $custom_field . ')</h4>';
?>
<tr class="hinweis">
<th>Hinweis:</th>
<td><?php $wpo_wcpdf->custom_field('Hinweis'); ?></td>
</tr>
<?php
}
}
——
Plugin Contributor
Ewout
(@pomegranate)
Hello Samuel,
I’m not sure what that code is supposed to do, but like this is will most likely throw a fatal error… You can fetch the custom field before displaying it and then checking if it’s empty, but if you want to limit this to specific products being in the order, the code becomes much more complex, and outside of the scope of free support. Contact me on support@wpovernight.com if you need my assistence with this!
add_action( 'wpo_wcpdf_before_order_data', 'wpo_wcpdf_custom_text', 10, 2 );
function wpo_wcpdf_custom_text ($template_type, $order) {
global $wpo_wcpdf;
$hinweis = $wpo_wcpdf->get_custom_field('Hinweis');
if ($template_type == 'invoice' && !empty($hinweis) ) {
?>
<tr class="hinweis">
<th>Hinweis:</th>
<td><?php $wpo_wcpdf->custom_field('Hinweis'); ?></td>
</tr>
<?php
}
}
Hi Ewout,
thank you for your help. In case I need assistence I`ll contact you on support.
Where can I mention you for your help?
Best, Samuel
Plugin Contributor
Ewout
(@pomegranate)
Hi Samuel,
You’re welcome! If you would like to leave review, you can do that
here on wordpress.org
Thanks in advance!
Ewout