Do you have another plugin that saves more information and want to display it in a PDF (like woocommerce booking or “Product Add-Ons”? Then you can use the custom field wizard to add this information in your pdf in seconds. All you need to do is this:
1.- Go to ‘Custom Fields’
2.- Click in ‘Open Custom Field Wizard’
3.- Select an order that has the information that you want to display. Then the plugin will inspect that order and will show you all the information that woocommerce is saving about that order, you just need to select the type of information that you want to display
Once you select the fields that you want to display you can also format them as a number, currency, date or even QRCode!
And thats it, now all you need to do is save and add your new field in your pdf template.
In a previous article i explained how to add QRCodes to apdf. This time i am going to explain how to do the same inside the invoice detail table, so you could create a QRCode for the product sku, order price, weight or basically any information of your products.
The process is pretty straight forward, all you need to do is this:
1.- Create a Custom Field
2.- Define which information you want to convert to QRCode, in this example i am going to convert the SKU of the product into a QRCode. To get the sku of the product i need this piece of code :
Note: I could use the same piece of code to get other information like:
line_subtotal:Price of the product without taxes
line_total: Price of the product with taxes
line_tax: Tax of the product
3.- Generate a QRCode with the information that i defined in my previous step like this:
4.- Use my new Custom Field in my table like this:
Thats it! If you have any question please let me know!
The invoice builder already comes bundled with a bunch of fields that you can pick from but you can create your own if those fields are not enough. If you want to create something more advance like a table that display your customer order history or a field that gets the order date and add two days to it (maybe you want to use that as the ‘shipping date’?) you need to use custom fields. In this tutorial i am going to show you how to do a very basic custom field which will show the current logged in user name in the invoice. In future tutorials i am going to show you how to do more advanced fields. So lets start =).
Creating or Editing a Custom Field
Important: The custom fields are a very powerful feature that let you do almost anything like contacting other servers or querying your site’s database so only admins are alowed to edit or create them.
1.- Open the custom fields builder:
2.- Select the custom field that you want to edit or create a new one.
The Custom Field Designer
The custom field designer consist of two main parts:
Name: The name of your custom field, this name is going to be used in the invoice designer.
Code: Here you can put the code of your custom field, this code has to be done using PHP and every sentence must end with a semi colon.
In the screenshot above i am getting the user data using wp_get_current_user() and then i am getting the user name using ->user_login, again, this need to be done with PHP.
Using a custom field in an invoice
Now that you have your custom field all you need to do is drop a ‘Custom Field’ item in your invoice
Then just click in the new item and select the custom field that you want to use =)
But what can i do if i don’t know PHP
Well, first of all i will be posting more useful snipets so keep checking this site, you might find the sniped that you need or if you don’t find it let me know =).