Posted: September 10, 2020 at 2:55 pm
I have an event where children under 4 years of age can attend for free, but they are still required to “purchase” tickets. As part of the registration, I have the user select “Number of children under 4 years of age.” From there, I’d like to automatically apply a discount equal to that number times the cost of the ticket.
I was trying to modify the code at the link below to do what I need it do, but I’m having a lot of difficulty understanding your documentation, and there seems to be some strange caching or something going on (I’ve removed the code, but the surcharge still shows up on my account, even with no tickets in the cart).
My questions are as follows:
1. What can I hook in to to add a “negative” line item to the cart?
If I can get some guidance on those two basic elements, I should be able to write the logic myself. I’m just having a difficult time deciphering your documentation.
To answer your questions:
You would create a Live Item using a negative value rather than positive.
In the link you provided simply changing THIS value to be negative should do it.
Sorry but I don’t follow this, you don’t use a hook to pull the registration data in. You can pull the the registration data from the transaction object, which in that example is available after THIS check.
I can give you examples of this, however, before you start working on this more the above snippet works when adding a transaction surcharge based selecting a payment method when you finalize the registration but there’s another which may suit your needs better here:
That snippet add a surcharge into the transactions line items based on the registration info question value(s) but before the payment options load, meaning the total is adjusted.
That uses 2 questions based on T-Shirt size and then qty, but you can alter it to be simply based on the qyt of a single question and you set the unit_price to be a negative number to add a discount rather than a surcharge.
Will that work better for you?