In this guide you will learn how to create and add custom fields to Paid Memberships Pro PDF Invoices. This can be anything from a value from a database table, post meta to user meta.

What Is A Custom Variable

A custom variable is similar to a WordPress shortcode, where it follows a specific layout standard and replaces this variable with dynamic data as previously mentioned. The custom variables follow the pattern of two opening curly braces, the keyword and then the two closing curly braces: {{example}}.

This data could be order data, tax, amounts or even user information. Since Paid Memberships Pro PDF 1.5+ we’ve included a function that will allow you to create your own custom variables to load any data you’d like!

Adding Custom Fields/Variables To PDF Templates

To add custom fields to the Paid Memberships Pro PDF Invoices Add On requires a bit of code and mapping data. Our code example should be able to help get you started so you can copy/paste and bring in some extra variables into your PDF templates.

The Code Explained

You will work with an associative array which will map keys to data and this is the crux of the variables and custom variables of the PDF templates. In the above example, we create a custom variable (or shortcode) {{company}} which will then be replaced with the custom field value of “company” for the user which the PDF belongs to.

You may copy and paste line 9 as many times as you would like and replace the key (custom variable) and assigned value to that key. Once you have added this code to your site these variables may be added into your PDF templates and will be replaced with the dynamic data when an order is created going forward.

In the screenshot below it outlines creating a custom field called {{user_name_example}} which fetches the user’s login name. View code sample.

Adding custom variable to PDF template via the visual template builder.

The output of the above example would be: “The user name is: Andrew”.

In this guide you should have learned how to create custom variables for Paid Memberships Pro PDF Invoices. If not, please reach out to our support for assistance as part of your purchase. This Add On does require Paid Memberships Pro to be installed in order to work correctly.