Posted: January 16, 2022 at 9:40 am
Hi there, For a custom function on my site plugin, I intend to hook into ‘AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment’ and execute some code if said transaction completed with the use of a promo code. I’m not sure if EE records this information anywhere in its custom database tables and I could just query the registration or transaction to find out if this is the case? If not, it means EE probably triggers some code when the user enters their promo code on the checkout page which in turns write the relevant promotion object entries. If so, it’d be interesting to know if there is a specific hook I can use for that action, or if there is any other way to make sure my code execute when the promotion object is created! Thank you! |
|
Hi there, When a promotion is applied to a transaction it generates line items linked to that transaction so yes, a promotion ‘usage’ is saved with a transaction but there isn’t a specific hook fired when that happens. You can pull the line items from a transaction to confirm if a promotion has been applied to it but the hook you want to use for this depends on you use case, can you add some more details on what you looking to do, the type of promotion and when it should run. For example, is this a 100% percentage discount or a fixed dollar discount? Is the above the only type of promotion you want this to work with? For example, if you have $10 off a promotion should the same code above still run? |
|
Hi Tony, Thank you for the initial discussion! The piece of code I am writing is basically: – Has transaction been made using a promo code? This code effectively in design is trying to ensure a promo code with say, 10 allowed uses, is counted down per ticket in the basket and NOT per transaction: the default way EE deals with promotions which is sadly not adapted to our needs. EE certainly knows the amount of tickets purchased after checkout hence my interest in using above hook, though I do not think it knows whether a promo code has been used or not at this stage, as it seems the POB is created after entering the code at checkout. The type of promotion SHOULD be irrelevant, but in this specific case it will be a 100% discount. It shouldn’t be triggered for every 100% discount, it should be triggered if the code promo used matches a specific code identifier which means we’re working with a specific type of promo. |
|
So, basically, you need a ticket scope rather than an event scope on promotions, meaning the promotion applies per ticket in both uses and discount rather than per event? For what you are trying to do I personally think the above hook is too late in the request, promotions increment uses as soon as they are added to the cart, not when the registration/transaction is finalized so I would likely use:
That’s a filter hook used to give you the ability to bypass the promotions add-on incrementing the promotion ‘uses’ count. Hook in there, increment the uses however you want to and then return I don’t have an example of doing exactly what you are requesting but I do have a simple ‘gift card’ proof of concept snippet that may help point you in the right direction: https://gist.github.com/Pebblo/c2dd51d7b5e117810d9b5b70b9366b87
I may be misunderstanding something here, but yes, the promotion object will only be created when a promotion is applied. How would EE create a promotion without knowing a promotion is being applied? |
|
Hi Tony, Thank you for this! It’s actually an interesting way of going about doing what I wanted to do, and after altering the snippet quite a bit I’m able to get to the result expected. I do notice that once the promotion is applied, event espresso display the current dollar amount in the transaction breakdown as: where PROMOTION Z dollar amount = 200 EVENT Y 10 tickets @ $10 = $100 TOTAL TO PAY = $100 This is likely to be really confusing for users as the prices do not add up. The calculations behaves correctly if dollar amount < transaction amount, such as: where PROMOTION Z dollar amount = 50 EVENT Y 10 tickets @ $10 = $100 TOTAL TO PAY = $50 I don’t believe there is an easy way to change EE’s behaviour in displaying the breakdown of the costs and discounts of a transaction, so it may be that I will need to hide the text with Javascript instead. But of course if you have a solution, i’d love to hear it! |
|
Hmmm, where do you see the above? What should happen is you see something like this: https://monosnap.com/file/j5bEuIgWCP4mgkuYr106YrCQzvRHzV Then because the transaction amount is now 0 (A promotion has been applied > than the total amount, SPCO automatically submits and goes to the thank you page with nothing to pay. |
|
Hi Tony, apologies, I think I formulated it wrong. It behaves indeed as you’ve shown when the discount effectively make the transaction $0, but I forgot to mention that these gift certificates ONLY apply to a type of event (identified by taxonomy). This means, if you have a basket with some tickets for an event the discount applies for ($event_y), and some tickets for an event it doesn’t ($event_z), then when discount amount > $event_y total, this is what would appear: where PROMOTION Z dollar amount = 200 The user effectively sees the following calculations in the table: 100 – 200 + 75 which is in fact -25 and not $75. They are being charged the right amount but it is confusing when seen on the checkout page. Any suggestion? I know this would be a workaround for a workaround as EE do not really support gift certificates, but if you have a code efficient idea to sort out the print of the checkout breakdown it could be great. My client would prefer hiding the line entirely in all types of transactions rather than risking confusing the user. Thanks! |
|
The support post ‘Hook into a registration where a promotion code has been applied’ 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.