PDF Invoices

Paid Memberships Pro PDF Invoices prints extra values with a placeholder. User Fields do not need code. The filter below is still valid for user meta that is not a User Field, and for data that is not stored on the user.

User Fields

For a Paid Memberships Pro User Field, copy the Name column and use {{field_name}}. Do not use the label. Steps and screenshots are in Adding User Fields to PDF Invoices.

Which path to use

SourcePlaceholderCode
User Fields{{birthday}}No. Use the Name column.
Other user meta{{legacy_member_id}}Still valid. Use the filter to format or rename it. A matching {{meta_key}} is also filled automatically.
Order notes, order meta, or a custom table{{notes}}Yes. Register it with the filter.

Add a placeholder with code

Add this to a custom plugin or a must-use plugin. The first argument is the placeholder list. Return that array or the new value is dropped.

<?php
/**
 * Add custom placeholders to Paid Memberships Pro PDF Invoices.
 *
 * Still valid for user meta that is not a User Field, and for order data.
 */
function my_pmpro_pdf_example( $data_array, $user, $order_data ) {
    // User meta that is not a User Field.
    $data_array['{{legacy_member_id}}'] = esc_html( get_user_meta( $order_data->user_id, 'legacy_member_id', true ) );

    // Order data that is not stored on the user.
    $data_array['{{notes}}'] = esc_html( $order_data->notes );

    return $data_array;
}
add_filter( 'pmpro_pdf_invoice_custom_variables', 'my_pmpro_pdf_example', 10, 3 );

In the template, {{legacy_member_id}} prints that user meta value. {{notes}} prints the order notes. A missing key, or an empty value, prints blank.

Filter arguments

ArgumentWhat it is
$data_arrayPlaceholder keys and values. Include the braces in the key, for example {{notes}}.
$userThe member, or false if that user no longer exists. For user meta, use $order_data->user_id.
$order_dataThe Paid Memberships Pro order. Use this for notes, totals, and other order values.

Add it to the template

  1. Go to Settings → PMPro PDF Invoices.
  2. Open the Tools tab.
  3. Click Create Template, or Edit Template if a custom template already exists.
  4. Place the placeholder where the value should print, then save.
PDF template editor with a custom placeholder added to the layout.
Add the placeholder in the template editor.

Saving the template does not rewrite PDFs already stored. Download a sample, then generate or regenerate invoices from the Tools tab. Button details are in Create, edit, and select a template.

Common mistakes

Using this filter for a User Field

User Fields already print from the Name column. The filter is for other values.

Fix: Use {{birthday}} for a User Field named birthday. Keep the filter for user meta that is not a User Field, or for order data.

Forgetting to return the array

The filter replaces the placeholder list with whatever you return. No return means the new token is dropped.

Fix: End the callback with return $data_array;.

The template token does not match the array key

The key must include both pairs of braces, and it must match the template exactly.

Fix: Set $data_array['{{notes}}'] and put {{notes}} in the template. No spaces.

Reusing a built-in placeholder name

Names such as first_name, invoice_code, and billing_city are already filled by the plugin.

Fix: Use your own token, such as {{legacy_member_id}}.

Stay in the loop!

15% off your next purchase, just for you 🎁

Sign up to receive your exclusive discount, and keep up to date on our latest news, products & offers!

We don’t spam, ever! Read our privacy policy for more info.