Title: insert custom fields into template
Last modified: August 30, 2016

---

# insert custom fields into template

 *  Resolved [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/)
 * Hi,
 * Can’t find an existing topic, so I just start a new one (apologizes if I create
   a double ticket)
 * Is it possible to insert custom fields into the template.
    I have fields like“
   our reference” and “your reference” where “our reference” is user to purchase
   the products with the supplier. And your reference is used by our clients to 
   insert their PO number.
 * When we confirm our purchase, we want to output our PO number in the “our reference”
   field on the invoice so we can lookup easy and fast running purchases.
    Our clients
   can insert their PO number via the checkout, and we want to output this information
   into “your reference” on the invoice.
 * Thanks for your feedback and support!
 * [https://wordpress.org/plugins/woocommerce-pdf-invoices/](https://wordpress.org/plugins/woocommerce-pdf-invoices/)

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

 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441641)
 * I am busy with this feature at the moment, so it will be available soon. 🙂
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441898)
 * Hello Bas,
 * Any update about this feature?
    I need to insert a custom field “purchase reference
   n°”.
 * Thanks for your soonest reply.
 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441901)
 * Did you add the custom field yourself or with a plugin? I need to know the database
   meta key to get the value of the custom field, this way I can give you the code
   to display it on the invoice.
 * Take a look at the get_post_meta function of wp.
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441902)
 * Hello Bas,
 * I’m using Admin Custom Order fields plugin
    [http://www.woothemes.com/products/admin-custom-order-fields/](http://www.woothemes.com/products/admin-custom-order-fields/)
 * Custom field “Onze referentie”
    [https://www.dropbox.com/s/mmzg1dw19kijxxm/Schermafdruk%202015-10-09%2014.56.57.png?dl=0](https://www.dropbox.com/s/mmzg1dw19kijxxm/Schermafdruk%202015-10-09%2014.56.57.png?dl=0)
 * Is this enough information?
    Otherwise you can send me an example code, I can
   have a look if I can tweak myself.
 * Thanks!
 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441903)
 * Unfortunately this is not enough. I need to know the key of the custom field.
   Please contact woothemes. I need more info to actually write example code.
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441904)
 * Hello Bas,
 * In the documentation I found this:
    The meta keys for each admin custom order
   field are in the format of _wc_acof_{id} where {id} is replaced by the integer
   id of the field. This id is clearly visible next to the label of each field you
   have created. In the dropbox link in previous post, you can see that my custom
   field has **ID 2**
 * WooCommerce Admin Custom Order Fields field id Field ID
    Once you know the id,
   you can use get_post_meta( $order_id, ‘_wc_acof_{id}’, true ) to get the value
   of that custom field for a particular order.
 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441905)
 * Great! You’ve found exactly what you need. 🙂
    You can add this to the template
   by using $this->order->id instead of $order_id.
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441908)
 * Bas,
 * I don’t get any value back with following line according your instructions:
 *     ```
       <span class="small-font"><?php printf( __( 'Onze referentie2: %s', $this->textdomain ), $this->get_post_meta( $this->order->id, '_wc_acof_{2}', true ) ); ?></span><br/>
       ```
   
 * How can I get the value from the custom field?
 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441911)
 * Try to find the value in your database. Also first try without the printf and
   just put the order_id hardcoded so you are sure it’s not a syntax error in the
   prinf or wrong order_id or something.
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441915)
 * OK, I found the problem and solved.
 * it’s not working with printf
 * I’m using following line, and this does the job:
 * echo ‘Onze referentie: ‘ . get_post_meta($this->order->id, ‘_wc_acof_2’, true);
 *  Plugin Author [Bas Elbers](https://wordpress.org/support/users/baaaaas/)
 * (@baaaaas)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441917)
 * Great work! 🙂
 *  [acropora](https://wordpress.org/support/users/acropora/)
 * (@acropora)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441948)
 * i’m using the same plugin for custom order fields. But i cant get the values 
   to show, it just shows the code on the invoice. Should i place it between a <
   table></table> ?
 *  Thread Starter [codeagency](https://wordpress.org/support/users/7grafix/)
 * (@7grafix)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441949)
 * You have to make sure you are placing your code between <?php and ?> tags.
    The
   template is just for the layout. Any dynamic part you want to insert, you can
   to embed/include with the opening and closing PHP tags.

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

The topic ‘insert custom fields into template’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices/assets/icon-128x128.png?rev=1128583)
 * [Invoices for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices/reviews/)

 * 13 replies
 * 3 participants
 * Last reply from: [codeagency](https://wordpress.org/support/users/7grafix/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/insert-custom-fields-into-template/#post-6441949)
 * Status: resolved