Support

Home Forums Event Espresso Premium Display custom promo code on ticket template

Display custom promo code on ticket template

Posted: May 27, 2021 at 11:13 am

Viewing 5 reply threads


ComedieTriomphe

May 27, 2021 at 11:13 am

Hi there,

My support question today is sort of a follow-up on my custom PHP promotion code topic two weeks ago, during which I successfully implemented a little code which creates new promotions every time someone buys a specific type of ticket.

Now, I have a custom ticket template which the buyer receives through the messages system for this specific event, which needs to display the aforementioned generated promo code.
The promo code is built from the first three letters of the surname, the transaction ID, and a unique identifier which helps tag the type of promotions.
To generate such promo code, I was simply using EE models in the checkout hook to find the attendee’s name etc. and do some simple string manipulation. All good.

Now, I want to display this code on the ticket generated by the messages system. What is the simplest way to do this? I would love it if I could simply use the shortcodes available to do the same simple string manipulation I did, but I don’t think it is possible. And I don’t think I can access the EE model system from within the messages either.

Could you help me out and point me in the right direction?

Thanks!


Tony

  • Support Staff

May 28, 2021 at 3:08 am

Hi there,

You can always use the model system within EE ๐Ÿ™‚

If I were doing this, I’d add a custom shortcode and we have some documentation for this here:

https://eventespresso.com/wiki/messages-system-how-to-add-custom-message-shortcodes/

An example of adding a shortcode to the EE_Transaction_Shortcodes (because you mentioned the above uses the transaction ID) can be found here:

https://gist.github.com/Pebblo/dc011b43b461064a831d

The contents of $data and $extra_data changes based on the message type and context but you can usually grab most of the data/object your need from within that. Use something like Kint Debugger to output those to the page and see what data you have available if you aren’t using an IDE like PHPStorm.

Does that help?


ComedieTriomphe

May 28, 2021 at 3:37 am

Hi Tony,
Great, thank you for the info.
No chance I could simply get to the model system directly in the template code without registering a shortcode? I’m fairly new to WordPress and PHP and we’re a little short with time to develop that one, it is such simple code once you get access to the data I was hoping not having to spend time learning how to register new shortcodes within EE hehe :).

But if that’s the way, no problem; I’ll start looking into it now.


Tony

  • Support Staff

May 28, 2021 at 4:25 am

No chance I could simply get to the model system directly in the template code without registering a shortcode?

I’m not sure I follow, how would you run that code and how would the code know where to run in the message system?

How would it know what registration is was related to?

In short, adding a custom shortcode to do this is the easiest and quickest option for you do it.

Iโ€™m fairly new to WordPress and PHP and weโ€™re a little short with time to develop that one, it is such simple code once you get access to the data I was hoping not having to spend time learning how to register new shortcodes within EE hehe ๐Ÿ™‚

Registering the shortcode is not really an issue here, the example function I gave you above gives you pretty much everything you need to register a new EE message shortcode.

Set the shortcode you want to add on Line 12.

Confirm that you are parsing that same shortcode one line 21.

Return whatever you want from within the if statement used to check the correct shortcode (your custom promotion code).

Getting the data you need to generate the matching promo is where it’s a little more tricky.

What is the code you are using to generate the promotion code?


ComedieTriomphe

May 28, 2021 at 10:19 am

Hey Tony,

I actually managed this pretty easily because the documentation is easy to follow, so all good!

Thank you.


Tony

  • Support Staff

May 28, 2021 at 2:52 pm

Awesome, I’m glad it helped ๐Ÿ™‚

Viewing 5 reply threads

The support post ‘Display custom promo code on ticket template’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso