Support

Home Forums Event Espresso Premium Is there a way to exempt a price type from getting discounted via promotions?

Is there a way to exempt a price type from getting discounted via promotions?

Posted: January 19, 2023 at 9:27 am


fuzzyminds

January 19, 2023 at 9:27 am

Hello,

We use EE for our course scheduling. Previously we had an absolute price for our courses for e.g. one ticket comprised of one price of ‘x’ amount. Recently we’ve changed our model and added a couple of price types and segregated our prices into 3 different heads. So now our event prices comprise of an ‘x’ price type + ‘y’ price type + ‘z’ price type. We’ve added these price types as a surcharge.

What we need to do now is, make sure that promotional codes can only be applied to a specific price type. For e.g. only ‘z’ price type will be discounted when a promotional code is applied.

We can also look at this problem from another angle and say that the ‘x’ and ‘y’ price types will not be discounted and the rest will be.

A more clear representation of this model using numbers is:

1) Price type ‘x’: $500
2) Price type ‘y’: $600
3) Price type ‘z’: $1000

Now when a user applies a promotional code, the discount should only be applied on the $1000, and leave the rest of the price i.e. $1100 intact. So that a discount code of -60% would yield a total price of $1100+$400(discounted)=$1500

Is there a way to accomplish this? TIA


Tony

  • Support Staff

January 23, 2023 at 4:38 pm

Hi there,

Right now, promotions apply to specific events, meaning they have an event ‘scope’ where you set them to apply to events as a whole.

To do the above, promotions would need to be altered to have a ticket ‘scope’ meaning you could set promotions to have the ability to apply only to specific tickets within an event.

Currently, that is not something we have available within Event Espresso.

To do this with the current set up, the Z ticket would need to be separated out into an additional event and then the user could use the Multi Event Registration add-on to add both to the cart. Only the event with the Z ticket would be set to apply on the promotion which would allow for the above pricing.


fuzzyminds

January 31, 2023 at 12:29 pm

Hi @Tony,

I understand the discount scope. Unfortunately the multi event registration add-on wouldnt work for our purposes.

Is there a way I can intercept a hook for promotion application and restrict it programmatically to the specific price type ids?

We are willing to implement any changes if they can be made by intercepting discounts. Can you please guide me on hooks and in this direction a little on priority? Our business is taking a hit because we are not able to do this. We have developer resources so we can implement custom scopes with a little help from you.

Thanks


Tony

  • Support Staff

February 1, 2023 at 5:01 am

I did some checking on this and we actually do have a POC snippet for ticket scopes available here:

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

You set the $applicable_promotion_tickets array up to be something like:

$applicable_promotion_tickets = [
    {PROMO_ID} => [{ticket_id}, {ticket_id}],
];

The snippet should do the rest for you.

So lets say you promotion ID is 111 and you want it to apply to ticket ID 77 and 88:

$applicable_promotion_tickets = [
    111 => [77, 88],
];

Should make the promotion only applicable to those tickets.

That help?


fuzzyminds

February 3, 2023 at 4:39 am

@tony
Thank you for the code snippet, we will see if we can make use of this for our scenario.

We don’t just want to exempt a ticket from promotion, but an entire price type. In summary we’re looking for a step further. Each ticket can have a different price type added to it, right? We want to exclude an entire price type from getting discounted.


fuzzyminds

February 3, 2023 at 7:44 am

To clarify further on my question,
A ticket has a base price and some price modifiers, we’re looking for a possibility to restrict the applicability of promotions on only the base price, so that a promotions doesn’t affect the prices added or subtracted by price modifiers.

I hope this context would help you understand better.


Tony

  • Support Staff

February 6, 2023 at 7:22 am

Hmm, that’s a very different situation from the above.

Excluding a specific price type from a promotion could be done by modifying the above snippet to pull in the specific price type set on a ticket, however, that doesn’t appear to be what you are looking for.

It sounds like what you want to do is apply a promotion only to the ticket base price (regardless of type?) and then apply the same price modifiers again based on the new price, is that correct?

If so it is likely possible but not something we have any kind of example for.

I think your would you would need to regenerate the line items for the ticket(s) manually for this to work.


fuzzyminds

February 9, 2023 at 7:38 am

This reply has been marked as private.


Tony

  • Support Staff

February 9, 2023 at 2:36 pm

We can’t support hacking up core files within Event Espresso or it’s add-ons so I can’t step through this with you as is.

By hacking up EED_Promotions::_get_payment_info() like this you basically freeze your site on the version you are running.

It looks like you need to update the $cart itself but I can’t be sure. I’ll check if there is another location/hook you can use to do this ‘correctly’.


fuzzyminds

February 11, 2023 at 12:08 am

Makes sense Tony.

Kindly let us know the correct way to accomplish this. We’re counting on your help.


fuzzyminds

February 14, 2023 at 9:51 am

@tony

Please look into our request as soon as you can. Thank you in Advance!


Brent Christensen

  • Support Staff

February 14, 2023 at 12:15 pm

Hi fuzzyminds,

I’m Event Espresso’s lead developer, because our promotions are currently only applied at the level of Events, what you needed to do is recalculate the promotion percent based on how much it actually reduces the event total.

try this:



add_filter(
    'FHEE__EE_Promotion_Scope__generate_promotion_line_item',
    'fuzzymindsGeneratePromotionLineItem',
    10,
    3
);

function fuzzymindsGeneratePromotionLineItem(
    array $line_item_args,
    ?EE_Line_Item $parent_line_item,
    ?EE_Promotion $promotion
) {
   $tickets = EEH_Line_Item::get_ticket_line_items($parent_line_item);
    if (empty($tickets)) {
        return $line_item_args;
    }
    $working_discount = 0;
    foreach ($tickets as $ticket) {
        if (! $ticket instanceof EE_Line_Item || $ticket->OBJ_type() !== 'Ticket') {
            continue;
        }
        $prices = $ticket->children();
        foreach ($prices as $price) {
            if (
                $price instanceof EE_Line_Item
                && $price->OBJ_type() === 'Price'
                && $price->total() >= 1000 // price where discounts apply
            ) {
                $working_discount += $promotion->calculated_amount_on_value($price->total());
            }
        }
    }
    if ($working_discount) {
        $prev_total = $parent_line_item->total();
        $new_total = $prev_total + $working_discount;
        $new_discount = 100 - ($new_total / $prev_total * 100);
        $line_item_args['LIN_percent'] = $new_discount *-1;
        $line_item_args['LIN_total'] = $new_total;
    }
    return $line_item_args;
}

The support post ‘Is there a way to exempt a price type from getting discounted via promotions?’ 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.

Event Espresso