Title: Discount Code Help
Last modified: August 31, 2016

---

# Discount Code Help

 *  Resolved [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/)
 * Hi Franky,
 * I needed help with creating a discount code for an annual event last year and
   you helped me out in this thread. [https://wordpress.org/support/topic/discount-code-4?replies=15](https://wordpress.org/support/topic/discount-code-4?replies=15).
 * At the end of that thread I came across a problem where the code was causing 
   the form to bypass the paypal screen when the discount code was entered, instead
   of just deducting the amount of one “ticket” from the total. You provided me 
   with new code which I believed worked last year but now I’m running into the 
   same problem.
 * Here’s the code I’m using:
 *     ```
       add_action('eme_insert_rsvp_action', 'FCNC_eme_coupons',20,1);
       /**
        * Custom function to calculate coupon code discounts for events
        */
        function FCNC_eme_coupons($booking) {
          global $wpdb;
          $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
          $discount = 36;
          $where = array();
          $fields = array();
   
       // Grab the coupon code from the extra answers
          $event_id = $booking['event_id'];
          $event = eme_get_event($event_id);
          $booking_id = $booking['booking_id'];
          $answers = eme_get_answers($booking_id);
       		$coupon = "";
               foreach ($answers as $answer) {
                   if ($answer['field_name'] == "Coupon") {
                      $coupon = $answer['answer'];
                   }
               }
   
       		if ($coupon == "TeenFriend") {
       	// If coupon code used, apply the appropriate price change
       	$price = $booking['booking_price'] - $event['price'];
   
               // now check $coupon for your wanted value
   
             $fields['booking_price'] = $price;
             $where['booking_id'] = $booking['booking_id'];
             $wpdb->update($bookings_table, $fields, $where);
          }
          return;
       }
       ```
   
 * Thanks!
 * [https://wordpress.org/plugins/events-made-easy/](https://wordpress.org/plugins/events-made-easy/)

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

 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279473)
 * The code you show here is not the code shown as example at the end of that thread.
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279767)
 * Thanks! Silly me. That part works now but I’m still running into the issue that
   if there’s only one RSVP and they’re using the coupon code which deducts 1 entry
   fee they’re still being brought to the Paypal screen.
 * Any ideas?
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279775)
 * If the paypal page shows up, it means the price is not 0.
    Show us the discount
   code you use now.
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279778)
 * The code is
 * > Friends
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279779)
 * On a similar note, how would I add additional coupon codes that deduct $5 from
   each ticket?
 * Thanks!
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279783)
 * I meant the php code, not the coupon code …
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279784)
 * Oops sorry.
 *     ```
       add_action('eme_insert_rsvp_action', 'FCNC_eme_coupons',20,1);
       /**
        * Custom function to calculate coupon code discounts for events
        */
        function FCNC_eme_coupons($booking) {
          global $wpdb;
          $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
          $discount = 36;
          $where = array();
          $fields = array();
   
       // Grab the coupon code from the extra answers
          $event_id = $booking['event_id'];
          $event = eme_get_event($event_id);
          $booking_id = $booking['booking_id'];
          $answers = eme_get_answers($booking_id);
          $seats = $booking['booking_seats'];
   
       		$coupon = "";
               foreach ($answers as $answer) {
                   if ($answer['field_name'] == "Coupon") {
                      $coupon = $answer['answer'];
                   }
               }
   
       		if ($coupon == "Friends" && $seats>1) {
       	// If coupon code used, apply the appropriate price change
       	$price = $booking['booking_price']*($seats-1)/$seats;
       	$price = sprintf("%01.2f",$price);
   
               // now check $coupon for your wanted value
   
             $fields['booking_price'] = $price;
             $where['booking_id'] = $booking['booking_id'];
             $wpdb->update($bookings_table, $fields, $where);
          }
          return;
       }
       ```
   
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279785)
 * Well … this seems rather obvious to me:
 *     ```
       && $seats>1
       ```
   
 * Your code will only be done if the number of reserved seats is more than 1 …
   
   Concerning your other question: $booking[‘booking_price’] is the price per seat,
   so if you want to reduce it with 5 if a certain copuon is used, you can use a
   similar function as the one you’re using already (again: drop the ” && seats>
   1 if not desired):
 *     ```
       if ($coupon == "xxx" && $seats>1) {
       $booking['booking_price']-=5;
       }
       ```
   
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279789)
 * Thanks so much!
 * One last thing. Is there a way to limit how many times a code can be used?
 * Thanks again.
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279790)
 * Sorry, currently not possible (since this is in fact your own code, it is not
   managed by eme).
    I’m still in the progress of implementing a more central EME-
   managed discount model, but it takes time …

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

The topic ‘Discount Code Help’ 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/)

 * 10 replies
 * 2 participants
 * Last reply from: [Franky](https://wordpress.org/support/users/liedekef/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/discount-code-help/#post-7279790)
 * Status: resolved