You can also add a custom row in the subtotal area, this custom row could either display a text or do a custom calculation
1.- Go to custom fields and create a new custom field:
2.- Create the custom field either using the custom field wizard or returning any value, the custom code below will just create a custom subtotal with the text ‘This is a custom row’.
Important: If you want to add this custom field in the subtotal area you need to select ‘Subtotal Row’ in the type of custom field
3.- Go to your pdf template and in the ‘invoice detail’ settings go to the ‘Subtotals’ section and click on Add custom subtotal
4.- Select the custom field that you created and click on ‘Add’
5.- Optional: Define a label for your custom row
And that’s it! With these changes your custom subtotal will be added to your table
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 (using the order id)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
How can you find the order number?
Generally, you can find the order number in the top section of the “Order” page
But there are some plugins that could modify this number and display a formatted version. If that is the case for you, you can still find the order number in the “Order” URL
4.- 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.
Getting Started
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 :
item[‘sku’]
Note: I could use the same piece of code to get other information like:
name:Product Name
qty:Quantity
weight:Weight
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 =).