Accessing custom fields in theme

I want to display my tax registration number based on which customer is in the invoice.
basically i sell to customers in EU and Canada and in the invoice theme i want to make it ‘automatically’ show the tax number of my business based on the customer.

So i created the following custom fields:

image

Basically, the idea is that i have two custom fields for my business to store the registration number and custom fields at Customer level to indicate which of the vat or hst number to show.

I have problem configuring the team as i am not very familiar with the syntax. This is what i have so far, but it gives me a null error:

                        {% for field in business.custom_fields %}
                            {% if (field.label == 'VAT Number' && custom_fields['Show VAT Number'] == 'Yes') %}
                            <div>{{ field.label }} {{ field.text }}</div>
                            {% endif %}
                            {% if( field.label == 'HST Reg. No' && custom_fields['Show HST Number'] == 'Yes' ) %} 
                            <div>{{ field.label }} {{ field.text }}</div>
                            {% endif %}
                        {% endfor %}

It’s funny how you know how to directly access custom fields but still use loops and logic to get them :wink:.

You can directly use this instead

{{ custom_fields['VAT Number'].label }}

Also use and instead of &&.

Thank you @Ealfardan

I can’t say i knew exactly what i was doing :smiley:

But now i managed to get it working this way:

{% if custom_fields["Show VAT Number"] and custom_fields["Show VAT Number"] == 'Yes' %}
<div style="font-weight: bold; padding-top: 10px">VAT # : {{ business.custom_fields["VAT Number"] }}</div>
{% endif %}

{% if custom_fields["Show HST Number"] and custom_fields["Show HST Number"] == 'Yes' %}
<div style="font-weight: bold; padding-top: 10px">HST # : {{ business.custom_fields["HST Reg. No"] }}</div>
{% endif %}
1 Like