Title: Discount Code
Last modified: August 22, 2016

---

# Discount Code

 *  Resolved [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/)
 * I currently have my RSVP form set to charge $25/pp. I’m trying to add a field
   for a discount code which certain attendees will receive and others will not.
   How can I do this so it passes the information along to the Paypal form?
 * Thanks!
 * [https://wordpress.org/plugins/events-made-easy/](https://wordpress.org/plugins/events-made-easy/)

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

 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855206)
 * See the doc site for discount code examples:
    [http://www.e-dynamics.be/wordpress/?p=305](http://www.e-dynamics.be/wordpress/?p=305)
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855358)
 * Hi Franky,
 * Just wanted to double check that the code below is the applicable code and I 
   also wanted to clarify how I set what the acceptable coupon code is. Thanks!
 *     ```
       add_action('eme_insert_rsvp_action', 'my_eme_discount_function',20,1);
       function my_eme_discount_function($booking) {
          global $wpdb;
          $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
          $where = array();
          $fields = array();
   
          $booking_id = $booking['booking_id'];
          $event_id = $booking['event_id'];
   
          if ($event_id == 5) {        /* put in the event_id that needs processing, or leave out this line to process all events */
             //echo 'EVENT ID='.$event_id .' Booking_id = '.$booking['booking_id'];
   
             $seats=$booking['booking_seats'];
             $price=$booking['booking_price'];
   
               // below a small example to check own input
       		$coupon = "";
               $answers = eme_get_answers($booking_id);
               foreach ($answers as $answer) {
                   if ($answer['field_name'] == "MY_FIELD_NAME") {
                      $coupon = $answer['answer'];
                   }
               }
               // 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)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855361)
 * In the forum on my site you find some examples. This one vies a discount of 10%
   if a custom field called “Coupon” contains the text “COUPON10”:
 *     ```
       add_action('eme_insert_rsvp_action', 'my_eme_coupons',20,1);
   
       /**
        * Custom function to calculate coupon code discounts for events
        */
   
       function my_eme_coupons($booking) {
       	global $wpdb;
       	$bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
       	$discount = 10;
       	$where = array();
       	$fields = array();
   
       	// Grab the coupon code from the extra answers
       	$event_id = $booking['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 == "COUPON10") {
       		// If coupon code used, apply the appropriate price change
       		$price = $booking['booking_price'] - ( $booking['booking_price'] * ($discount / 100));
   
       		$fields['booking_price'] = $price;
       		$where['booking_id'] = $booking['booking_id'];
       		$wpdb->update($bookings_table, $fields, $where);
       	}
       	return;
       }
       ```
   
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855398)
 * Thanks so much Franky! One last question. How can I get it to deduct the price
   of one ticket from the entire amount? for example if it was $20/ticket and someone
   entered the code and was booking only 1 space it would be free but if someone
   else was booking 3 spots and entered the code it would be $40 instead of $60.
 * Thanks!
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855401)
 * The price for a single seat is in $event[‘price’] , so:
 *     ```
       add_action('eme_insert_rsvp_action', 'my_eme_coupons',20,1);
   
       /**
        * Custom function to calculate coupon code discounts for events
        */
   
       function my_eme_coupons($booking) {
       	global $wpdb;
       	$bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
       	$discount = 10;
       	$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 == "COUPON10") {
       		// If coupon code used, apply the appropriate price change
       		$price = $booking['booking_price'] - $event['price'];
   
       		$fields['booking_price'] = $price;
       		$where['booking_id'] = $booking['booking_id'];
       		$wpdb->update($bookings_table, $fields, $where);
       	}
       	return;
       }
       ```
   
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855443)
 * After using the code below
 *     ```
       add_action('eme_insert_rsvp_action', 'my_eme_coupons',20,1);
       /**
        * Custom function to calculate coupon code discounts for events
        */
        function my_eme_coupons($booking) {
          global $wpdb;
          $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
          $discount = 25;
          $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;
       }
       ```
   
 * it stopped forwarding visitors to the paypal payment page and is discounting 
   the entire booking amount instead of just discounting the event price.
 * What am I doing wrong?
 * TIA!
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855444)
 * The discount code is for a single-price event, maybe you’re using something else?
   
   Also: if the price is 0, then the payment page is not shown of course.
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855472)
 * The event is set to be single-price the only amount I have listed for price is
   25. I understand that if someone is only purchasing a single ticket and uses 
   the discount code the price would equal 0 and they wouldn’t be brought to the
   payment page but that doesn’t explain why someone who books 4 tickets isn’t being
   charged for 3 and being brought to the payment page.
 * Any other ideas?
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855473)
 * I don’t see anything wrong with this code, so maybe send me a email with login
   details so I can see for myself.
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855474)
 * How do I find your email?
 * Thanks so much!
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855475)
 * My email : [liedekef@telenet.be](https://wordpress.org/support/topic/discount-code-4/liedekef@telenet.be?output_format=md)
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855476)
 * Emailed you. Thanks!
 *  Plugin Author [Franky](https://wordpress.org/support/users/liedekef/)
 * (@liedekef)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855479)
 * This is the code that works, since in fact the booking_price is the price per
   seat in a booking, not the total price.
    Maybe it is useful to add a total price
   booking, or a discount field …
 *     ```
       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 = 25;
          $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 == "TeenFriend" && $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_id;
             $wpdb->update($bookings_table, $fields, $where);
          }
          return;
       }
       ```
   
 *  Thread Starter [fcvolunteer](https://wordpress.org/support/users/fcvolunteer/)
 * (@fcvolunteer)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/discount-code-4/#post-5855481)
 * Thanks!!!

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

The topic ‘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

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

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