Support

Home Forums Event Espresso Premium Discount by Tickets

Discount by Tickets

Posted: October 9, 2019 at 8:17 am


Kevin@microgridknowledge.com

October 9, 2019 at 8:17 am

I see this feature was discussed in 2015 and 2016. https://eventespresso.com/topic/discounts-by-ticket/

It seemed like over 80 of your users voted in favor of having discount codes being applied to certain ticket types. Any update on this feature?

It is really something I need to continue my subscription. What would it cost to sponsor the development of this feature as Seth suggested?


Josh

  • Support Staff

October 9, 2019 at 8:49 am

Hi,

One update that did happen since then is the promotions add-on now includes hooks that allow for programmatically setting a specific ticket to allow a specific promotion. An example of how to use the hooks is hosted here:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-promotions/bc_ee_ticket_scope_promotions.php

With the above, a PHP developer could build out a system of discounts per ticket to your specifications.

If you’d prefer to look into sponsorship of a ticket per promotion user interface, to be included in an official update to the promotions add-on, you can reach out to Seth via this form:

https://eventespresso.com/rich-features/sponsor-new-features/


Kevin@microgridknowledge.com

October 9, 2019 at 9:55 pm

I have tested out the code and it does indeed limit promo codes to specific tickets. However it ignores the use limit, which I still need

The filter “FHEE__EED_Promotions__add_promotion_line_item__bypass_increment_promotion_scope_uses” appears to be responsible for bypassing the use limit. I’ve tried setting the return value to false as well as commenting out the entire add_filter() line in hopes of enforcing the use limit. No luck.

Do you know if there’s a fix for this?


Josh

  • Support Staff

October 11, 2019 at 2:28 pm

The filter is supposed to bypass the use limit, because what’s happened is the event scope is no longer in effect. There isn’t a check for “ticket scope usage limit”. Usage limits are applied to and checked against for the event scope.

What you could do in this case is add some additional logic and a loop at the very end of the main loop that gets the event ID from the tickets, then applies the usage for the promotions to the event scope. At that point it will work because the plugin still checks for the event scope’s usage limit.

e.g. add the following just before the end of the main foreach loop

// get ticket object
$ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID());
if ($ticket instanceof EE_Ticket) {
    // get related event object
    $event = $ticket->get_related_event();
    if ($event instanceof EE_Event) {
        foreach (range(1, $applicable_items[0]->get('LIN_quantity')) as $i) {
            // increment usage to event scope
            try {
                if ($promotion->scope_obj()->increment_promotion_scope_uses(
                    $promotion,
                    $event->id()
                )) {
                    continue;
                }
            } catch (Exception $e) {
                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
            }
        }
    }
}


Kevin@microgridknowledge.com

October 14, 2019 at 10:45 am

This is great. Only issue I found is that the use limit isn’t applied until after a transaction pushes the usage count to equal or greater than the use limit.

For example, let’s say promo code XYZ has a use limit of 4. The newly added foreach loop will allow me to apply the code to 5 tickets. After I complete the transaction, the promo code is no longer valid and prompts as such.

Is it possible to make the use limit apply for this use case?


Josh

  • Support Staff

October 15, 2019 at 3:18 pm

The newly added foreach loop will allow me to apply the code to 5 tickets.

What’s actually allowing you to apply the code to 5 tickets is the change to the ticket scope from event scope (the first part of the custom code). The newly added foreach loop only adds to increment the count of promo code uses.

You can add a conditional to the top of the innermost loop and that will prevent going over the limit:

if($promotion->get('PRO_uses') <= $promotion->redeemed() + 1) {
    continue;
}

Normally the above check isn’t needed because only one scope item would be applied regardless of the number of tickets.


Kevin@microgridknowledge.com

October 15, 2019 at 7:58 pm

It still allows that extra ticket to work with the code. Did I place it in the correct loop?


foreach ($ticket_line_items as $ticket_line_item) {
    if (! $ticket_line_item instanceof EE_Line_Item) {
        continue;
    }
    foreach ($applicable_promotion_tickets as $promotion_ID => $promotion_tickets) {
       <strong> if($promotion->get('PRO_uses') <= $promotion->redeemed() + 1) {
	    continue;
	}</strong>

        // rest of code
    }
}


Kevin@microgridknowledge.com

October 15, 2019 at 8:00 pm

Sorry, in the above code block I tried to bold the added code to emphasize its placement. “” and “” isn’t in my actual code.


Josh

  • Support Staff

October 16, 2019 at 10:25 am

It still allows that extra ticket to work with the code.

Can you explain what you mean by this? It may help to know the exact scenario you’re testing because I’m probably not testing the changes the same way you’re testing. If you can outline a list of testing steps we can examine further.

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  Josh 8 hours, 36 minutes ago ago

Topic Tags

Notifications

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