Title: Check discount code
Last modified: August 22, 2016

---

# Check discount code

 *  Resolved [montgoger](https://wordpress.org/support/users/montgoger/)
 * (@montgoger)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/check-discount-code/)
 * Hi again,
 * This topic follow a precedent one:
 * [Discount code for multiprice and multiseat events](https://wordpress.org/support/topic/discount-code-for-multiprice-and-multiseat-events?replies=25)
 * Like you told me Franky I check your code
 * [http://www.e-dynamics.be/wordpress/?cat=41](http://www.e-dynamics.be/wordpress/?cat=41)
   and add a function check_coupon() to my function.php… For sure it’s doesn’t work
   and I miss something ;-). There is my problem, I don’t understand how your code
   return an information block the user and avoid him to get on the #eme-rsvp-message
 *     ```
       add_filter('eme_eval_booking_filter','check_coupon');
       function check_coupon($event) {
          $event_id=$event['event_id'];
   
       // Place here your VOUCHER CODE and PERCENT don't forget to declare in my_eme_discount_function()
          $vouchers = array(
                        'montgoger2noel',
                        'montgoger3easter',
                       );
   
       // Recovery of VOUCHER CODE
          $coupon = "";
          $answers = eme_get_answers($booking_id);
          foreach ($answers as $answer) {
              if ($answer['field_name'] == "#_FIELD{1}") {
                 $coupon = $answer['answer'];
              }
          }
   
          foreach ($vouchers as $voucher) {
            if ($coupon !='' && $coupon<>$voucher) {
              // bad form entry
              return array(0=>1,1=>'Bad coupon code');
           }
          }
       }
       ```
   
 * Thanks to the community to help me 🙂
 * [https://wordpress.org/plugins/events-made-easy/](https://wordpress.org/plugins/events-made-easy/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/check-discount-code/#post-5501791)
 * As said before: don’t use #_FIELD{1}, it will not work!!! Use a real field name.
   
   Also: your last foreach will always cause a “bad coupon code” to be returned.
   Try this:
 *     ```
       $coupon_found=0;
          foreach ($vouchers as $voucher) {
            if ($coupon !='' && $coupon==$voucher) {
               $coupon_found=1;
            }
          }
          if (!$coupon_found)
             return array(0,'Bad coupon code');
          else
             return array(1,'');
       ```
   
 *  Thread Starter [montgoger](https://wordpress.org/support/users/montgoger/)
 * (@montgoger)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/check-discount-code/#post-5501848)
 * Everything is perfect 😀
 * I know you told me this already but i have few reason to didn’t listen at you:
   #
   1 It’s work like this…
 * #2 I wish i could change it, i search but i didn’t find how to get a “real field”.
   the name of my field is litteraly declare like this in Form fields. If you explain
   me exactly i will do it…
 * #3 And because I’m As stubborn as a mule 😉
 * Thanks Thanks thanks
 *     ```
       add_filter('eme_eval_booking_filter','check_coupon');
       function check_coupon($event) {
          $event_id=$event['event_id'];
   
       // Place here your VOUCHER CODE and PERCENT don't forget to declare in my_eme_discount_function()
          $vouchers = array(
                        'montgogernoel',
                        'montgoger3easter',
                       );
   
       // Recovery of VOUCHER CODE
          $coupon = "";
          $answers = eme_get_answers($booking_id);
          foreach ($answers as $answer) {
              if ($answer['field_name'] == "#_FIELD{1}") {
                 $coupon = $answer['answer'];
              }
          }
   
          $coupon_found=0;
          foreach ($vouchers as $voucher) {
               if ($coupon !='' && $coupon==$voucher) {
                   $coupon_found=1;
               }
          }
          if (!$coupon_found)
                 return array(0,'Check your voucher code again please');
          else
                 return array(1,'');
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Check discount code’ is closed to new replies.

 * ![](https://ps.w.org/events-made-easy/assets/icon-256x256.png?rev=1856035)
 * [Events Made Easy](https://wordpress.org/plugins/events-made-easy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-made-easy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-made-easy/)
 * [Active Topics](https://wordpress.org/support/plugin/events-made-easy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-made-easy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-made-easy/reviews/)

## Tags

 * [check](https://wordpress.org/support/topic-tag/check/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [discount](https://wordpress.org/support/topic-tag/discount/)

 * 2 replies
 * 2 participants
 * Last reply from: [montgoger](https://wordpress.org/support/users/montgoger/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/check-discount-code/#post-5501848)
 * Status: resolved