Title: Display custom text field by modifying function.php
Last modified: August 31, 2016

---

# Display custom text field by modifying function.php

 *  Resolved [uebersax](https://wordpress.org/support/users/uebersax/)
 * (@uebersax)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/)
 * Hi there,
 * we are using your plugin and are happy with it.
    We would now like to add a custom
   text field by using the function.php. The label we set for the field is: Hinweis
   and the content will change sometimes. The field should only be shown on the 
   pdf-invoice.
 * Thank you for your help.
 * PS: We are using the WC Field Factory Plugin.
 * Kind regards,
    uebersax
 * [https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Contributor [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319846)
 * Hello Samuel,
    You can find instructions for adding a custom text in our documentation
   here: [Print a custom text after the order details table](http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/pdf-template-action-hooks/#example-2-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](http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/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](http://docs.wpovernight.com/general/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
 *  Thread Starter [uebersax](https://wordpress.org/support/users/uebersax/)
 * (@uebersax)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319848)
 * 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](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319866)
 * 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>
       ```
   
 *  Thread Starter [uebersax](https://wordpress.org/support/users/uebersax/)
 * (@uebersax)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319877)
 * 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?
 *  Thread Starter [uebersax](https://wordpress.org/support/users/uebersax/)
 * (@uebersax)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319902)
 * 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](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319973)
 * 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](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/support@wpovernight.com?output_format=md)
   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
           }
       }
       ```
   
 *  Thread Starter [uebersax](https://wordpress.org/support/users/uebersax/)
 * (@uebersax)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319974)
 * 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](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319984)
 * Hi Samuel,
    You’re welcome! If you would like to leave review, you can do that
   [here on wordpress.org](https://wordpress.org/support/view/plugin-reviews/woocommerce-pdf-invoices-packing-slips)
 * Thanks in advance!
    Ewout

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Display custom text field by modifying function.php’ is closed to new
replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Ewout](https://wordpress.org/support/users/pomegranate/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/display-custom-text-field-by-modifying-functionphp/#post-7319984)
 * Status: resolved