Home / Archive / MemberPress: Display Custom Field Value Instead of Customer Name in PDF invoice
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Display Custom Field Value Instead of Customer Name in PDF invoice

This code snippet automatically adds the custom field value or the customer's full name at the beginning of the "Bill To" section in the PDF invoice. If the custom field value is empty, it displays the customer's full name.

The “mepr_company_name” slug will need to be replaced with your custom field slug.

Code Preview
php
<?php
function mepr_change_invoice_bill_to( $invoice, $txn ) {
	$user = $txn->user();
	// Get company custom field.
	// Replace 'mepr_company_name' with the custom field slug.
	$company = get_user_meta( $user->ID, 'mepr_company_name', true );
	// Return company name if not empty
	$name = ( !empty( $company ) ? $company : $user->full_name() );
	
	$invoice['bill_to'] = $name . '<br/>' . $invoice['bill_to'];
	
	return $invoice;
}
add_filter( 'mepr-pdf-invoice-data', 'mepr_change_invoice_bill_to', 10, 2 );

Comments

Add a Comment