The answer posted by Interlated can be problematic and display incorrect name if the contact doing the contribution has different name specific for billing fields. For Eg -
- A contribution page is created with profile = "Name and Address".
- When the page is visited online, the profile + billing profile is loaded on the form.
- User unchecks the option
My billing address is the same as above
and enters a different name and address for billing fields.
The {contact.display_name}
will load the original contact name in the mail receipt instead of the expected billing name.
We've also come across this problem and saw some receipt missing the billing fields. This seems to be due to name
field in civicrm_address
table being set to NULL due to some reason.
Not yet sure how to replicate this, but below patch have fixed the problem for us.
diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php
index af3dbd233d..31f69c9996 100644
--- a/CRM/Core/BAO/Address.php
+++ b/CRM/Core/BAO/Address.php
@@ -504,6 +504,10 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
$values = [];
CRM_Core_DAO::storeValues($address, $values);
+ //Fill name of contact if empty.
+ if (empty($address->name) && !empty($address->contact_id)) {
+ $address->name = CRM_Contact_BAO_Contact::displayName($address->contact_id);
+ }
// add state and country information: CRM-369
if (!empty($address->location_type_id)) {
$values['location_type'] = CRM_Utils_Array::value($address->location_type_id, $locationTypes);