Display customer's title in Print PDF invoice in Magento

I am trying to customize the PDF file created by the Print PDF button in our Magento admin.

After researching, I believe the file I need to modify is called: header.phtml

Here is the existing code:

<?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getOrder()->getBillingAddress()->getTitle() ); ?>

Open in new window

This is displaying the name as stored in the customer's Default Contact Address, followed by the title in parenthesis.

The problem is that it is displaying the incorrect title. I want it to show the title from the Default Contact Address, but it is displaying the title from a section in the customer information called Additional Address Entries.

I took a guess and tried changing my code to this:

<?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getCustomer()->getTitle() ); ?>

Open in new window

But that simply displays nothing in the parenthesis. Next, I tried this:

?php echo sprintf( '%s (%s)', $this->getCustomer()->getName(), $this->getOrder()->getShippingAddress()->getTitle() ); ?>

Open in new window

That seems to also display the incorrect title. How can I change this to display the Default Contact Address title rather than the others?

Thank you!
Brad BansnerWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Not sure what you mean by title
If you are looking for the gender
$customer->getGender(); // ID

Check here there is a list of customer info you can display
Brad BansnerWeb DeveloperAuthor Commented:
I need the "title" of the customer (i.e., President, C.E.O., etc.). In my database, I see (among other things):


That last one is what I need.

When I go to: https://www.mydomain.com/magento/customer/address/

...I see a Default Contact Address, Default Shipping Address and "Additional Address Entries". This:


Open in new window

Is pulling in the Additional Address Entries "title" field, for some reason. I'm trying to get the Default Contact Address "title" field instead, but not able to.
Brad BansnerWeb DeveloperAuthor Commented:
Also, I should point out, I'm not looking for the "title of the customer who is currently logged in". I'm in the admin interface generating a PDF of an invoice. I need the "title of the customer who placed the order".
SolarWinds® IP Control Bundle (IPCB)

Combines SolarWinds IP Address Manager and User Device Tracker to help detect IP conflicts, quickly identify affected systems, and help your team take near instantaneous action. Help improve visibility and enhance reliability with SolarWinds IP Control Bundle.

Is title is a custom field, because by default this field is not on buyer account (maybe this have changed).
Are you using a third party extension for you invoice or for buyer account?
Are you using the Opensource version or other version?
Brad BansnerWeb DeveloperAuthor Commented:
Maybe it is a custom field. I'm not sure, because I took this project over from another company. I'm also not sure the answer to your other questions. The fact that you are saying this is not a default field definitely tells me something. If it is a custom field (which is my assumption at this point), is there some way to bring that data in and display it on the PDF? I understand that may be way outside the scope of this question.

Hi the Magento Version is displayed at the bottom of the page when you are logged in the backend.

If you can contact the previous company that may be useful to have more information about what the have customized.
And this will be important to know for future updates.

You can check the installed extensions related to invoice or account.
The extension can be in one of the following directory:

This is the Magento folder structure :

To give you an idea how custom field work, this may help you to find the appropriate variable.

There is a lot information you can find on Magento web site

If you have the enterprise edition
Brad BansnerWeb DeveloperAuthor Commented:
Magento version:

Contacting the previous developer isn't really an option at this point, unfortunately.

Here are the folders within "community" and "local":


ReadingThermal (client name)

That seems like a lot? So all of those are various third-party extensions? It seems this is not going to be a simple change at all, even just changing one field like this. I may have to get a Magento sub-contractor involved, I think, unless there is some simple solution that I'm not understanding.

Thank you.
Yes you should hire someone that have experience with magento.
 Magento can be complicated even for experienced programmer.

Or if you find out the related extension, you can contact the extension author, you can get the info in readme file, or in the extension listed in the backend.

I think it is this extension have something for login so maybe related: http://www.magepsycho.com/

As you will see these company have a lot of extensions.

Brad BansnerWeb DeveloperAuthor Commented:
Here is the solution we arrived at:

//The 'company’ is a custom attribute added to a customer/address model.

//So we have access to a customer, lets get it’s ID:
$customer_id = $this->getCustomer()->getId();

//get handle to Magento’s model
$customerObj  = Mage::getModel('customer/address')->load($customer_id);

//get the custom attribute
$company = $customerObj->getData('company');

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brad BansnerWeb DeveloperAuthor Commented:
Thanks for your help and advice, this one was just a little more complicated. I hope this answer helps someone in the future.
Brad BansnerWeb DeveloperAuthor Commented:
Found the solution outside of EE.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.