I realise this is an old discussion now but I am playing with just that at the moment so I thought I would post my observations here.
What is described below is based on experimentation and deduction, so with this caveat…
I wanted FAO (as in “for attention of”) line showing above the customer’s name and address on invoices but I did not want it to be part of the customer name itself. I also did not want it to show for the second time at the bottom of the invoice with all the custom fields. I have found that the following seems to work.
In Settings, I added a custom field called “FAO” to “Customer” (ticking “Show custom field on printed documents”)
I have found that this field becomes available as {{ custom_fields.FAO }} within the template code. So I added the line
<div>{{ custom_fields.FAO }}</div>
Just above
<div>{{ recipient.address | newline_to_br }}</div>
<div>{{ recipient.identifier }}</div>
My template is based on the Smooth Navy template. This adds my FAO information above the name / address (without the field name).
As @Attila says above, all custom fields are output together (and with their labels) at the bottom of the invoice by this code:
{% for field in custom_fields %}
<tr>
<td colspan="99">
<div style="font-weight: bold; padding-top: 20px">{{ field.label }}</div>
<div>{{ field.text | newline_to_br }}</div>
</td>
</tr>
{% endfor %}
In order to avoid having my FAO field printed here as well, I filter it out while iterating through the custom_fields array:
{% for field in custom_fields %}
{% if field.label != "FAO" %}
<tr>
<td colspan="99">
<div style="font-weight: bold; padding-top: 20px">{{ field.label }}</div>
<div>{{ field.text | newline_to_br }}</div>
</td>
</tr>
{% endif %}
{% endfor %}
If you had multiple fields to filter out, you can modify the if statement, for reference see https://shopify.github.io/liquid/tags/control-flow/
What I don’t fully understand is this - when I added a custom field with the same name “FAO” to Sales Invoice, both “FAO” fields were correctly filtered out at the bottom and the “FAO” from “Customer” was still showing on top as before… And the new field was also stored in the custom_fields array as “FAO” because when I removed the “if” filter, both “FAO” fields got printed at the bottom. So avoid having the same custom field names for different objects!