How to inject custom text dynamically in email

  • Posts: 134
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
1 day 22 hours ago #367601

-- HikaShop version -- : 5.1.6
-- Joomla version -- : 5.3.1
-- PHP version -- : 8.3.12

Hi,

I'm trying to inject different custom texts, based on which product(s) the customer has bought, in the Order Status Notification email. Those texts must give product-specific information to the customer.

For example, Customer 1 has bought a software license, and I want to inject that chunk of text in the ORDER STATUS NOTIFICATION email:
"You bought a download version. You need to install the app first, then activate it with a serial number which you can find below...etc.etc.". Customer 2 has ordered a subscription, I want to inject that text instead of the first one: "Thanks for signing up. Now you need to do thais, and that, and then, blah blah..."

I have created a Checkbox custom field called "email_tags" for the Product table, where I add values for each custom text I want to inject. I display those checkboxes on the backend only, so that for each product, I can select the value(s) I want to inject in the email (there can be more than one selected value). Then I create text chunks in the text overrides for each of the values defined in the "email_tags" custom checkbox, for example: MYTXT_DLD="You bought a download version. You need to..."

So far so good... But I'm not sure how to proceed from here. What is the easiest way to get Hikashop to pick the texts that correspond to the checked boxes when generating the Order Status Notification email?

Thank you for your help!

Please Log in or Create an account to join the conversation.

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
1 day 18 hours ago #367603

Hi,

Well, you have two options:

- Since you requested the easiest way, here it is: Edit the email via the System>Emails menu and in its "HTML version" area, just add the tag {VAR:product.email_tags} inside a td tag between the

<!--{START:PRODUCT_LINE}-->
and
<!--{END:PRODUCT_LINE}-->
The system will then replace automatically your tag with the selected values in the database.
There are two drawbacks with this method:
1. you can't have different translations for the text. You need to have the text directly in the "value" input of each row of values of your custom field
2. you can't display your text outside of the row of the product on the products listing table in the email

- The more complex solution is to modify the "preload section" of the email (via the System>Emails menu).
There, there are several modifications you want to make:
1. You want to add an extra row to the $vars array.
2. Inside the array looping on the products "foreach($data->cart->products as $item) {", you want to take the data from $product->email_tags, explode it, use JText::_() in order to translate it, and then appending it to your entry in $vars. Ideally, you want to change that the value is not already appended so that you don't have the same text several times if the customer purchase several products with the same text checked in them.
3. In the "HTML section" of the email, you can then use the key of your extra row in $vars in a tag like {VAR:key} where key is the key of your extra row in $vars.
The advantage here is that you can place the tag anywhere in the HTML, and the texts will be translated
The drawback is that it requires some coding to be done by a PHP developer.

Last edit: 1 day 17 hours ago by nicolas.
The following user(s) said Thank You: earmaster

Please Log in or Create an account to join the conversation.

  • Posts: 134
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
1 day 17 hours ago #367608

Thank you Nicolas, that was very helpful. I'll try to get a php developer help me do this.

Last edit: 1 day 17 hours ago by earmaster.

Please Log in or Create an account to join the conversation.

  • Posts: 83989
  • Thank you received: 13604
  • MODERATOR
1 day 13 hours ago #367609

Great. Note that we can potentially work on such custom jobs. If you're interested, you can go through our contact form:
www.hikashop.com/support/contact-us.html
For what you want here, we would charge 40€ (without taxes)

Please Log in or Create an account to join the conversation.

Time to create page: 0.058 seconds
Powered by Kunena Forum