Support

Home Forums Event Espresso Premium Custom shortcode in messaging system: series of tickets

Custom shortcode in messaging system: series of tickets

Posted: June 7, 2021 at 2:17 am

Viewing 7 reply threads


ComedieTriomphe

June 7, 2021 at 2:17 am

Hey there,

This is a follow-up to a previous support thread in which I successfully set up a custom shortcode to be used in the messages (thanks, Tony!).

This shortcode actually display a code that was previously generated during checkout which is then used by the buyer to redeem some promotion.
In the specific occasion when a buyer purchases two or more tickets of these kinds, a matching amount of codes are generated, and I’d need to print one on each of the tickets the buyer will then receive.

I know this is somewhat posible because EE4 can display tickets ID on each ticket within a transaction, but I’m not sure how I can do the same within my own custom shortcode.

My shortcode doesn’t need to look for the code and retrieve it from the database, because it’s easy enough that it can build it from the informations it receives from the ticketing generation process, but I would need to be able to iterate over x many tickets were bought and display one on each ticket following this method.

Of course, I’m open to suggestions if this isn’t the right way to go about it!

Thanks


Tony

  • Support Staff

June 7, 2021 at 4:04 am

Hi there,

HERE is a quick link to the previous thread for any future readers.

If you are using the snippet I gave you in that thread then you are adding a transaction based shortcode. Which means you have access to the EE_Transaction using the code on lines 23-24.

Confirm it is indeed an EE_Transaction object before trying to use it (Line 27)

The EE_Transaction object has a registrations() method, which can be used to pull all of the registrations linked to that transaction, it will return an array of EE_Registration objects, which I’m sure you are already familiar with to get what you need.

Or if you are looking to include the info in a specific section of the message template I’ll need to know which section to check what is available there.


ComedieTriomphe

June 7, 2021 at 5:54 am

Hi Tony,

That’s correct; I can successfully get to the array of EE_Registration object; but how do I tell the shortcode that it needs to print array[i] on the first ticket then array[i+1] for any subsequent ticket that was purchased in a single transaction? I’m not sure how the custom shortcode code I’ve written knows every single execution in a transaction needs to be taking place on the next array element.


Tony

  • Support Staff

June 7, 2021 at 6:05 am

With a transaction shortcode, it doesn’t (and can’t) know that you want to loop through an array if the shortcode is being processed multiple times.

Where in the message template are you including the details?


ComedieTriomphe

June 7, 2021 at 6:26 am

Ah, this makes sense of course! Still getting my head around EE’s ecosystem.

The shortcode is placed within the message template in its own div, so that I can position its output wherever I want with HTML/CSS (on my other thread with the tickets issue, you’ll see it displaying a code which is in fact the promo code).
I do need access to the transaction info to generate the code, which is basically registration number + some string manipulation; and and added number depending on how many tickets were bought.


ComedieTriomphe

June 8, 2021 at 6:41 am

Should I maybe take a look in the Messages model to find what’s available to me within this context?


Tony

  • Support Staff

June 8, 2021 at 2:27 pm

Because your using this shortcode within the ticket template and need the value to be unique for each registrant, you can’t use a transaction-based shortcode. Well, technically you could but I wouldn’t.

I’d add my shortcode to the EE_Recipient_Details_Shortcodes library for this.

This example should help: https://gist.github.com/Pebblo/b8b9b804bcd709c988ad6794f990b4dc


Tony

  • Support Staff

June 8, 2021 at 2:30 pm

Note that you can pull the EE_Registration object from the $recipient (my examples uses the attendee, which you don’t need).

It should be something like:

$registration = $recipient->reg_obj;

if( $registratio instanceof EE_Registration ) {
    //Do something with registration object.
}
Viewing 7 reply threads

The support post ‘Custom shortcode in messaging system: series of tickets’ 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