Support

Home Forums Event Espresso Premium Automatically discounting an order based on a registration fieldq

Automatically discounting an order based on a registration fieldq

Posted: September 10, 2020 at 2:55 pm


weblinxinc

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).

https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_add_cart_modifier.php

My questions are as follows:

1. What can I hook in to to add a “negative” line item to the cart?
2. In the hook, how can I retrieve the registration data that the user entered?

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.


Tony

  • Support Staff

September 15, 2020 at 5:09 am

Hi there,

To answer your questions:

1. What can I hook in to to add a “negative” line item to the cart?

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.

2. In the hook, how can I retrieve the registration data that the user entered?

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:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_ee_add_product_surcharge.php

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?

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 1 week, 4 days ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!