Support

Home Forums Event Espresso Premium Remove Coupon on Some Events but not others?

Remove Coupon on Some Events but not others?

Posted: January 6, 2016 at 4:01 pm


denise

January 6, 2016 at 4:01 pm

Hi,

I would like to remove the option to put in a coupon on some events but not others.

How would I go about doing that?

Thanks!
Denise


Garth

  • Support Staff

January 6, 2016 at 4:54 pm

With the Promotions Add-on you can allow promotion codes on some events and not others: https://eventespresso.com/product/eea-promotions/ https://eventespresso.com/wiki/ee4-promotions-add-on/


Josh

  • Support Staff

January 6, 2016 at 5:17 pm

Hi Denise,

It sounds like you want to promo code input to not appear at all if it’s a specific event? Is that right? If so, the input gets added via the WordPress plugin API’s hooks, and can be removed via the same hooks.

Here’s a link to some code that you can add to your site that will add a check for an custom field set in the event that’s named “coupon” and a value for that field set to “no”. If the condition is met, it will unhook the action that adds the promo code input.

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

You can add the above to a functions plugin or into your WordPress theme’s functions.php file.


denise

January 15, 2016 at 8:32 pm

Hi Josh,

Sorry I finally got to try this. I added the code to my “custom plugin”. When I created the event, under the Custom Field box of the event I added a new name “coupon” and under value I put “no”

Does that seem right? On the final checkout page when I go to pay, the box still shows up. Should I have put this snippet somewhere else? I have quite a few hooks for EE4 already in there…

Thanks
Denise


Josh

  • Support Staff

January 16, 2016 at 8:26 am

The custom plugin should be fine. The reason that it’s not working on your site is because the Multi Event Registration plugin is active. The code in the snippet that I shared with you checks to see if the Multi Event Registration plugin is active and if it’s active, then it does nothing. This is because there could be two events in the cart, then one allows promo codes and the other one doesn’t, which complicates things.

You can try removing the check for Multi Event Registration from the above code by removing the check on line 8, which is

if ( ! defined( 'EE_MER_PATH' ) ) {

then (very important) you remove the closing bracket from line 27, which is

}

This will allow the code to run if Multi Event Registration is activated. You’ll find that if you have two registrations where one of the events allows promo codes, and the other event does not, it may still show the promo code field or it may not depending on the order that the events were added to the cart.


denise

January 22, 2016 at 10:34 am

Hi Josh,

That worked, however I am also using the code below to add text before the voucher box. So your function removes the box, but not the .prepend text. Could you share the snippet to remove that as well?

function add_groupon_message_to_promo_input() {
?>
<script>
jQuery( document ).on(‘ajaxComplete ready’, function() {
jQuery(‘div#ee-single-page-checkout-dv input#ee-promotion-code-input’)
.attr(‘placeholder’, ‘if you have a voucher or gift card, type the word “VOUCHER” here’);
jQuery(‘div#ee-spco-payment_options-reg-step-form-payment-options-before-payment-options’)
.prepend( ‘Type the word “VOUCHER” in the field below if using a discount coupon or gift certificate‘);
});
</script>
<?php
}
add_action( ‘AHEE__payment_options__reg_step_start’, ‘add_groupon_message_to_promo_input’ );

THANK YOU VERY MUCH FOR YOUR WONDERFUL SUPPORT!

Regards
Denise


Josh

  • Support Staff

January 22, 2016 at 11:06 am

Hi Denise,

What you can do there is move the add_action that adds .prepend text to the other function into an else statement like this:

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' ));
 } else {
add_action( 'AHEE__payment_options__reg_step_start', 'add_groupon_message_to_promo_input' );
}

This way, the .prepend JavaScript will only load if there’s a promo code box being displayed.


denise

January 22, 2016 at 12:57 pm

Hi Josh,

This is my new code snippet. It successfully is removed from events where I set “coupon” to “no” but on my regular events, the coupon box appears, BUT it is now empty with none of my special text and instructions. I assumed I would remove the add_action that was under my ‘add_groupon_message_to_promo_input’ was that correct?

/* 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() {

$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’ ));
}
else {
add_action( ‘AHEE__payment_options__reg_step_start’, ‘add_groupon_message_to_promo_input’ );
}
}
}
}
}
}

}


Josh

  • Support Staff

January 22, 2016 at 1:36 pm

Not necessarily because load order comes into play here. The other thing you can try is removing the custom message function from the AHEE__payment_options__reg_step_start action when you also remove the add_promotions_form_inputs function from the
FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options
action


denise

January 22, 2016 at 2:27 pm

Thank you. I tried your recommendation, but it seems I am back to where I was when we started where my text and coupon box show up fine, but on the events I want to supress them the -.prepend text is present but the coupon box is removed. Here is the new function, did I set it up right?

/* 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() {

$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’ ));
remove_action( ‘AHEE__payment_options__reg_step_start’, ‘add_groupon_message_to_promo_input’ );
}
/*else {
add_action( ‘AHEE__payment_options__reg_step_start’, ‘add_groupon_message_to_promo_input’ );
}*/
}
}
}
}
}

}


Josh

  • Support Staff

January 25, 2016 at 11:58 am

Hi Denise,

It gets kind of tricky because of the way the hooks fire since AJAX is involved. My last suggestion here is leave the code to remove the coupon field on some events intact, and make a few tweaks to the code that adds the extra message so it only adds the message if the promocode field is actually here. Here’s a link to the updated gist where I made a few tweaks to the promo code “groupon goes here” message:

https://gist.github.com/joshfeck/3b76f817378162b9601c


denise

January 25, 2016 at 3:16 pm

Hi Josh,

Excellent! That worked! Both texts get displayed or shown properly!

Thank you!

Denise


Josh

  • Support Staff

January 25, 2016 at 4:31 pm

You’re welcome.

The support post ‘Remove Coupon on Some Events but not others?’ 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