Support

Home Forums Event Espresso Premium Promotion Discount Not affecting Tax applied by a Price Modifier

Promotion Discount Not affecting Tax applied by a Price Modifier

Posted: March 27, 2020 at 3:08 pm

Viewing 8 reply threads


mlevison

March 27, 2020 at 3:08 pm

We have to use price modifiers to represent the tax as EE does not allow for different tax amounts for different events (HST applies in some provinces but only GST in others). When applying promotion codes it applies a discount after the tax is calculated which leaves us with an incorrect tax amount on the invoices/receipts.
I saw a possible solution on this thread here. Which I think will adjust the tax displayed on the invoice/receipt.
Is there a way that this could be applied that would account for the different tax rate (price modifier) being applied to an event’s tickets?
Are there plans to make the tax type/amount selectable by event as I understand that currently you can only have one tax rate for an entire account.


Josh

  • Support Staff

March 31, 2020 at 10:54 am

This code snippet is one solution:

https://gist.github.com/joshfeck/d4c013dd1b64807fee2e8d4c4d237456

This example code could be modified to work per event, but the way it works as-is involves adding a “Billing Address Province” question to the registration form. So if the registrant selects Alberta, it adds 5% at checkout. This solution might work for you because of instead of setting the tax rate on the event, the location of the attendee determines the tax rate.

The end result works out like this:

https://slack-files.com/T02SY781D-FUP143GET-176322084d

The custom code snippet can be added to a functions plugin.


mlevison

March 31, 2020 at 11:08 am

We need the tax rate tied to the event location not the location of the attendee so I will have to modify it to make it work the way we need it.

I will let you know if I need any assistance with the modifications.


Josh

  • Support Staff

March 31, 2020 at 12:41 pm

In that case, the logic in that first method wouldn’t be needed (since the logic is based on the answer of a reg. form question).

In that last method, the EE_Checkout object is passed in. You can get the event via the EE_Checkout object and add in logic there. e.g.

if ( $checkout instanceof EE_Checkout ) {
    $transaction = $checkout->transaction;
    if ( $transaction instanceof EE_Transaction ) {
        $registrations = $transaction->registrations();
        $registration = reset( $registrations );
        if ( $registration instanceof EE_Registration ) {
            $event = $registration->event();
            if ( $event instanceof EE_Event ) {
                // logic here based on event
            }
        }
    }
}


mlevison

April 1, 2020 at 2:23 pm

Thanks, Josh, I have managed to turn this into a working plugin but I do have one quirk.
I had planned on using this to get to the venue details for the active province:
if ( $event instanceof EE_Event ) {
$VNU_ID = espresso_venue_id( $event->ID() );
}
But the venue Id always comes back as 0

As a workaround I have done this:
if ( $event instanceof EE_Event ) {
foreach ($event->venues() as $venue):
$event_location = $venue->state();
endforeach;
}

I see plenty of examples using the first technique in the support forum but it hasn’t worked for me.


Josh

  • Support Staff

April 1, 2020 at 2:58 pm

espresso_venue_id() is template tag, and the template tag functions are likely not loaded into the request yet since the code you’re working with isn’t going into a template file.

You could do this to get the venue object from the event object:
$venue = $event->get_first_related('Venue')
and just in case if there’s an event that doesn’t have a venue, you can add one more check like this:

if($venue instanceof EE_Venue) {
  $event_location = $venue->state();
}


mlevison

April 1, 2020 at 3:35 pm

Thanks!

That works nicely and cleans up the code a bit.

Not only does this fix the problem of promotion discounts not affecting the calculated tax but it also removed the need for applying Price Modifiers to every ticket type.

Is it worth sharing the working code back to this thread?


Josh

  • Support Staff

April 1, 2020 at 3:42 pm

That’d be much appreciated. Since the forums don’t format code well, putting the code into a gist or pastebin is best. If that’s not too much trouble.

Otherwise, you can wrap the code in code tags or backticks like
`code start
code end`


mlevison

April 1, 2020 at 3:58 pm

I have added the code to Pastebin. This is the first time I’ve shared code this way and I hope that it works for everybody:

https://pastebin.com/yFZcH1ED

Viewing 8 reply threads

The support post ‘Promotion Discount Not affecting Tax applied by a Price Modifier’ 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