Skip to Content

New J2Commerce 6.6.5 is out. Here is everything in the release.

See What’s New
Account
Enter the email address on your account.
Forgot your username?
Enter your password.
Forgot your password?

Or continue with

Open Public Category: Technical Support / Bugs Ticket #475

How to replace [BILLING_STATE] with the Zone Code in email templates?

This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Conversation

Antonio Cornacchia

Hello

is it possible to replace [BILLING_STATE] with the Zone Code in email templates?

Thanks

Olivier Buisard Staff

Hello,

have you tried [CUSTOM_BILLING_FIELD:ZONE_ID]? I believe this will return the id of the zone code, therefore it will be necessary to create an advanced template file where would could have the retrieval of the code from the id through a database call.

Olivier.

Antonio Cornacchia

Hello

using [CUSTOM_BILLING_FIELD:ZONE_ID]  in the email does not produce any results, neither the zone nor its code.

Olivier Buisard Staff

Ok.

In the advanced template, you have access to the $order object.

I believe you can get the id for the zone with $order->billing_zone_id.

A database call can then be made to get the code corresponding to this id.

Let me know if you can see the zone id when adding <?php echo $order->billing_zone_id ?> to the template.

Olivier.

Antonio Cornacchia

Hi

using JCE, it removes the code from the template. So, using the code view I added it after [BILLING_COUNTRY], in the test email I simply get: billing_zone_id ?>

Anyway, is zone_id the Zone Code, that is what I need?

Attachments

zone-code.jpg
Olivier Buisard Staff

You have to be using the advanced template file, not the simple template editor. The advanced templates uses a code editor so there is no removal of code there.

Once you are able to see the id, then we can go to the next step and do a database query and actually get the code of the zone.

Olivier.

Olivier Buisard Staff

Hi Antonio, you cannot add PHP in this version of the email template. 

I am talking about the advanced templates, not the advanced settings.

In the 'Basic settings' tab, go to the 'Template editor' option and select 'Advanced template file'. This is higher level, and requires some coding knowledge, though. Most people stay on the simple editor, which is much easier to use.

So the trade off: 

  • keep the simple editor and use the allowed short codes only,
  • use the advanced editor and allow other elements to be added to the email.

Olivier.

Olivier Buisard Staff

I apologize if I was unclear... When you open an email templates, in the basic settings of the email template itself.

Olivier.

Olivier Buisard Staff

Thanks Antonio,

you won't get any positive result if you use the simple editor, because the PHP is not interpreted in this 'what you see is what you get' environment. That is why, to modify code through php, you need to use the advanced editor (https://docs.j2commerce.com/design/email-templates#how-to-create-an-email-template-). On that page, we explain you can use the simple editor (recommended for casual users) and the advanced template files, which you can add php to, for advanced users. In the screenshot, the 'Template editor' option is what you need to change. However, if you don't know php, this is going to be more confusing for you.

Olivier.

Antonio Cornacchia

Hello Oliviaer, I finally figured out where and how to select the advanced editor; I was confusing it with the advanced settings.
Thank you, I'll try to figure out if it's something I can do or not.

Attachments

Screenshot 2025-10-01 alle 17.38.47.png
Olivier Buisard Staff

Super, Antonio!

Yes, let me know if that is too complex.

If you figure it out, let me know and I can then give you the code to call the database and retrieve the zone code from the zone id.

Olivier.

Olivier Buisard Staff

I will add this as a request for improvement for a future release, Antonio.

Olivier.