Support

Home Forums Event Espresso Premium Promo Code Problem

Promo Code Problem

Posted: October 30, 2024 at 9:44 am

Viewing 7 reply threads


mlevison

October 30, 2024 at 9:44 am

Several years ago I had received help via this forum to have the Promo Code addon only allow the codes to be applied to “Regular” tickets. The final solution created and is visible near the bottom of this thread:
https://eventespresso.com/topic/promo-code-for-specific-ticket-types/

Unfortunately, this has stopped working as intended and it is denying Promo Codes on all ticket types. We have not made any changes to this code (used in a plugin) since we implemented it.

Can you point me in the right direction to see why the ticket filter is no able to identify tickets with the name “Regular”?

Thanks


Tony

  • Support Staff

November 1, 2024 at 10:03 am

Hi there,

I’ve just gone through and tested that snippet locally and it appears to be working correctly for me:

https://monosnap.com/file/NOtoRWunBtyGjGsLenhXAoaMWF2iY7

Thats exactly the same event with a ticket called ‘Regular’ and ‘Admission’, like this:

https://monosnap.com/file/8j4XHWsVKwEUyxZ2l3cSLYWsHwxi1B

The promotion is TEST and is a 50% discount, applied to the event in question:

https://monosnap.com/file/xAkctKu3ZA5jsO9d8TWHr4UdFcUAPv

and:

https://monosnap.com/file/KtZFyQs0AQNmYO3GVTArozZvdCsIqh

(Note this is a new, clan site I’ve just spun up for testing this, so it only has this event and that single promotion)

Am I using a different setup to you here?


mlevison

November 1, 2024 at 2:38 pm

I had only been testing using existing codes created by the site administrator. I have created some of my own test codes and when I first create them they work on both Regular and other tickets, not what we want. Once I have tested them a couple of times and not made any changes to them, they are then denied on non-Regular tickets but when using them on the Regular tickets I get the following error “An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.”

This is very difficult to debug with the inconsistent results but I will see if I can figure out the problem. Any insight you might have on the above error might be useful.

Thanks


mlevison

November 1, 2024 at 2:43 pm

To add to my previous comment, when I try any of our active codes on Regular tickets, I get this error:
“An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.”
I get denied with the correct response when using the codes on non-regular tickets.
Do you have any idea as to what might be wrong?


Tony

  • Support Staff

November 1, 2024 at 3:00 pm

“An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.”

Will generally be from a fatal error being thrown and then either no response is received on the ajax request, or garbage is received and EE doesn’t know what to do.

Check your servers error logs for fatal around when the above is thrown.

Or add this snippet to your sites wp-config.php file:

https://eventespresso.com/wiki/troubleshooting-checklist/#wpdebug

THen retest until you get the above.

Then check in /wp-content/debug.log for any errors


mlevison

November 1, 2024 at 3:50 pm

Thanks for that. I have enabled the error logging and this appears to be the relevant error generated:

[01-Nov-2024 21:45:24 UTC] PHP Fatal error: Uncaught DivisionByZeroError: Division by zero in /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/lib/scopes/EE_Promotion_Event_Scope.lib.php:643
Stack trace:
#0 /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/lib/scopes/EE_Promotion_Event_Scope.lib.php(574): EE_Promotion_Event_Scope->calculateAndApplyPromotionBeforeTaxes(Array, Object(EE_Line_Item), Object(EE_Promotion))
#1 /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/EED_Promotions.module.php(1149): EE_Promotion_Event_Scope->calculateAndApplyPromotion(Array, Object(EE_Line_Item), Object(EE_Promotion), true)
#2 /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/EED_Promotions.module.php(790): EED_Promotions->generate_promotion_line_items(Object(EE_Promotion), Array, true)
#3 /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/EED_Promotions.module.php(758): EED_Promotions->submitPromoCode()
#4 /nas/content/live/aprthemetest1/wp-includes/class-wp-hook.php(324): EED_Promotions::submit_promo_code(”)
#5 /nas/content/live/aprthemetest1/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(”, Array)
#6 /nas/content/live/aprthemetest1/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#7 /nas/content/live/aprthemetest1/wp-admin/admin-ajax.php(207): do_action(‘wp_ajax_nopriv_…’)
#8 {main}
thrown in /nas/content/live/aprthemetest1/wp-content/plugins/eea-promotions/lib/scopes/EE_Promotion_Event_Scope.lib.php on line 643

Does this tell you anything useful?


Tony

  • Support Staff

November 1, 2024 at 4:00 pm

It tells me the ticket_count is being returned as 0 and the code is then using that to try and devied the promotion value.

This code:


$ticket_line_items = $this->getApplicableItemChildren($event_line_item);
$ticket_count      = 0;
foreach ($ticket_line_items as $ticket_line_item) {
    $ticket_count += $ticket_line_item->quantity();
}
$original_promo_amount = $promotion->amount();
$promo_amount          = null;
$remainder             = 0;
if (! $promotion->is_percent()) {
    // fixed amount promotions need to be split between ALL the tickets
    $promo_amount = round($original_promo_amount / $ticket_count, 6, PHP_ROUND_HALF_DOWN);
    // calculate any leftovers like when dividing $10 by 3
    $remainder = round($original_promo_amount - ($promo_amount * $ticket_count), 6);
}

So $ticket_count is 0

When is why you have line items for a ticket which have a QTY of 0.

How are you testing this?


mlevison

November 1, 2024 at 5:08 pm

This reply has been marked as private.
Viewing 7 reply threads

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

Event Espresso