I am busy with this feature at the moment, so it will be available soon. š
Hello Bas,
Any update about this feature?
I need to insert a custom field “purchase reference n°”.
Thanks for your soonest reply.
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.
Hello Bas,
I’m using Admin Custom Order fields plugin
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
Is this enough information?
Otherwise you can send me an example code, I can have a look if I can tweak myself.
Thanks!
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.
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.
Great! You’ve found exactly what you need. š
You can add this to the template by using $this->order->id instead of $order_id.
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?
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.
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);
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> ?
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.