Support

Home Forums Event Espresso Premium Limit promotion code to specific ticket class/type

Limit promotion code to specific ticket class/type

Posted: November 1, 2019 at 6:14 am


holyfeld

November 1, 2019 at 6:14 am

I have an event with three ticket types. I want to create a promotion code that applies to two of the three ticket types.

Early Bird -> Promo code applies
Group Rate -> Promo code does not apply
Standard -> Promo code applies

How may I do this? I do have a custom site plugin for other EE display tweaks.

Version 4.10.1.p


Tony

  • Support Staff

November 1, 2019 at 7:21 am

Hi there,

Officially, you can’t with the current version.

The promotions add-on applies promotions to events rather than tickets within events.

However, we do have a snippet that can work for some use cases here:

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

You set up the $applicable_promotion_tickets array on Line 5 to have the ID of the promotion as the key, then and array of ticket IDs

So lets say you promotion ID is 10 and the ID of the 2 tickets you want it to be available on is 22 and 26, your array would look like this:

$applicable_promotion_tickets = array(
    10 => array( 22, 26)
);

That promotion will then only apply to those tickets.

Is that what you are looking for?


holyfeld

November 1, 2019 at 12:02 pm

I worried when I looked at the code in github, until I found I only needed to change one line, and the snippet was very specific about not changing any other code. Nicely done.

The solution works as described.

When I tested a generic “declined” message was displayed, not the declined message in the Promotion. I didn’t find an obvious setting in General Settings or an event message to change. What am I missing?

As I added the code to my site plugin, I noticed the snippet completely disables the Promotion field when I set a custom field to a specific value. This would actually be preferable. When the ticketid == 25, do not show the Promotion code box. Can this be done?


Tony

  • Support Staff

November 5, 2019 at 5:32 am

When I tested a generic “declined” message was displayed, not the declined message in the Promotion. I didn’t find an obvious setting in General Settings or an event message to change. What am I missing?

Hmm, strange.

Which type of decline are you testing here? No more uses?

If you can add some details of what you have set up I’ll see if I recreate locally and see what is happening.

As I added the code to my site plugin, I noticed the snippet completely disables the Promotion field when I set a custom field to a specific value.

It does? Can you add some more details on what you are doing here?


holyfeld

November 5, 2019 at 10:49 pm

Hmm, strange.

Which type of decline are you testing here? No more uses?

If you can add some details of what you have set up I’ll see if I recreate locally and see what is happening.

I modified the github code mentioned Nov 1 with this line for event 13, ticket types 23 & 24 which are to be included in the promotion code.

$applicable_promotion_tickets = array( 13 => array(23,24));

ticket type 25 is for a group rate (2 to 4 participants) and should not be included in the promotion.

the promotion code is for $ 100 off. The decline message in the promotion configuration is

“Declined
Promotion Codes not accepted for Group Registrations”

When I test the group registration, the promotion field shows. When I type in the promotion code, I get the following pop-up.

promotion error code

This indicates the reason may be a typing error, not a “You can’t have the discount error”.

It does? Can you add some more details on what you are doing here?

I run another event for which promotion codes do not apply. For those events, I create a custom field “coupon”, with the value “no”.

I believe this code came out of github.

// don’t display promo code input for specific events by setting Custom field to coupon == no
add_action( ‘AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment’, ‘jf_ee_promo_field_meta_key_override’, 10 );
function jf_ee_promo_field_meta_key_override() {
if ( ! defined( ‘EE_MER_PATH’ ) ) {
$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout ) {
$transaction = $checkout->transaction;
if ( $transaction instanceof EE_Transaction ) {
foreach ( $transaction->registrations() as $registration ) {
if ( $registration instanceof EE_Registration ) {
$event = $registration->event();
if ( $event instanceof EE_Event ) {
// in this case, the Custom Field name is ‘coupon’ and value is ‘no’
$meta_key_value = get_post_meta( $event->ID(), ‘coupon’, true );
if ( ! empty( $meta_key_value ) && $meta_key_value == ‘no’ ) {
remove_action( ‘FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options’, array( ‘EED_Promotions’, ‘add_promotions_form_inputs’ ));

Thinking about the dynamics, I’d really like to not display the promotion field for group registrations (ticket 25) rather than display a Decline message. I’m not sure this can be done, but thought I’d ask.


Tony

  • Support Staff

November 8, 2019 at 6:40 am

Ok, so the message you posted is the ‘no applicable items notice’, because the promotion used can’t be applied to the event and no others can apply to the cart it shows the above.

That message can be changed, but not to include the specific promotion code declined message as it doesn’t have access to it currently. It would also change it for all instances of the ‘no applicable items’ notice.

I believe this code came out of github.

My apologies, I misunderstood this and thought you were referring to the original snippet for applying promotions to specific tickets.

That snippet works on a custom field set on the events but it is possible to do something similar using ticket ID’s, to do that you would do something like this:

https://gist.github.com/Pebblo/c09ff7a1ee5ac618a41771a901661814

Set the Ticket ID’s in the array on line 24:

https://gist.github.com/Pebblo/c09ff7a1ee5ac618a41771a901661814#file-tw_remove_promo_input_for_specific_tkts-php-L24

If any of the ID’s set there match the ID’s of any of the tickets that are in the cart, the promotion input field will be removed.


holyfeld

November 8, 2019 at 11:50 am

My apologies, I misunderstood this and thought you were referring to the original snippet for applying promotions to specific tickets.

My original expression of what I am doing was muddled. I realized it after I reread my text.

Set the Ticket ID’s in the array on line 24:

https://gist.github.com/Pebblo/c09ff7a1ee5ac618a41771a901661814#file-tw_remove_promo_input_for_specific_tkts-php-L24

How interesting. Line 24 in the routine is exactly what I need!

First level testing reveals that:

1. For group tickets (25), the promo code field does not show.
2. For early bird, the promo code field does show, and calculates correctly.

I appreciate your help improving the registration experience for the workshop!


Tony

  • Support Staff

November 11, 2019 at 6:01 am

You’re most welcome, I’m glad that worked 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, 1 day ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[for="input_96_5_3"]
[for="input_96_5_3"]
[gravityform id=96 title=false description=false]
  • This field is for validation purposes and should be left unchanged.
[i]
[i]
[gravityform id=69 title=false description=false]
  • This field is for validation purposes and should be left unchanged.