Posted: 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! |
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/ |
|
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. You can add the above to a functions plugin or into your WordPress theme’s functions.php file. |
|
|
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 |
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
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. |
|
|
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() { THANK YOU VERY MUCH FOR YOUR WONDERFUL SUPPORT! Regards |
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. |
|
|
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*/ $checkout = EE_Registry::instance()->SSN->checkout(); } |
Not necessarily because load order comes into play here. The other thing you can try is removing the custom message function from the |
|
|
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*/ $checkout = EE_Registry::instance()->SSN->checkout(); } |
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: |
|
|
Hi Josh, Excellent! That worked! Both texts get displayed or shown properly! Thank you! Denise |
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.