Posted: May 9, 2016 at 4:22 pm
I have successfully implemented a credit system into EE4 using this hook: AHEE__thank_you_page_payment_details_template__after_each_payment When a person purchases a ticket, they receive a credit. After so many credits, they receive a free class. But I need to know how to get the number of tickets that were purchased in the transaction so I can add that amount of credits to their account. Can anyone help me? |
|
There’s an example in EE core that you can follow where in the EE_Cart class there’s a all_ticket_quantity_count() method. It returns the total quantity of tickets in the cart. |
|
Hey Josh, I did a search for how to apply it and I’m not sure if I’m calling it correctly. I’ve tried your information from this post: https://eventespresso.com/topic/getting-total-amount-of-tickets-in-cart/ I attempted without and then ended up trying it with this code the header.php:
Neither way worked. In the custom functions.php credit code:
Nothing is happening at all. No error and no change in the amount of credits. Do I need to load an object instance of something else? |
|
In this case, you wouldn’t call the load_core() method in header.php, instead you can call the method in your function file. |
|
It still for some reason is just returning 0 as the total tickets Josh, even though I have 2 tickets in the cart. I would think that $ticketcount variable would be sufficient enough. |
|
You might be calling the method too late and the cart is empty at that point then. Instead, since the $payment object is passed to the
You’ll need to be sure to pass in the $payment object when you call the function like this:
|
|
I passed in the $payment object and used the code you provided, but it did not increase the credits in the usermeta at all. |
|
It might help to know the context of how you used the code I provided. If you put the same code in a function and return it, it does return the number of tickets in the transaction, so the issue is likely in your code. |
|
No problem Josh. The code is in the custom functions.php plugin. Here is the full code:
|
|
It’s adding credits when I try the code out on my site. The issue I see with the code in its present state though is it will add more credits each time the thank you page is loaded or refreshed. You might try the
hook instead. This will help ensure that the credits are added only one time per transaction. |
|
I wish I had good news, but adding that hook breaks the template for me and I’m just left with an infinite spinning wheel. I added an is_page check instead and if need be I’m sure I can add other parameters, but unfortunately, the code is just not working for me at all. Now the only other thing I can think of why it is not working: I am putting in a discount code which gives me a 100% discount on priced ticket. So technically, the amount of the total cost of the ticket is $0. However, I would think that we are just counting registrations for the event in that transaction, not the actual amount, from the looks of the code. |
|
Hey Josh, This issue has been resolved and I have the credit system working for now. I went around EE4 and looked into what was on the pages themselves. I came up with a creative solution for this. To sum up the idea of how it works: There is a “Thank You” page where EE4 gives information about the purchase (Registrant Name, REG Code, and REG Status). On that thank you page are some links including “edit info” and “resend email”. There are also 2 additional links: ?e_reg_url_link and ?token=1 which is present twice). Anything more than those 2 links are actual registrations, which are the “resend email” links visible on the page. What I did was create a function to determine the amount of links on the page using the WordPress wp_extract_urls function and then subtracted those 2 extra links to get the total amount of registrations. I created a hidden meta field which turns off allowing credits only on this page, so that if someone refreshes the page, they cannot just keep getting credits, and obviously, the only way back to this page is by purchasing a ticket. They would have to leave the page in order to re-enable their ability to get more credits. As far as clicking on that edit info button and returning, there is another hidden meta field that holds temporary credits and if someone lands on the “Registration Checkout” page and those temporary credits exist, it is deducted from their user meta data until they land back on the Thank You page again. If they land on any other pages, those temporary credits are set to 0 so nothing gets deducted. |
|
The support post ‘Get Number of Tickets Purchased By Attendee Per Event’ 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.