Events Made Easy › Forums › How do I … › Split: Coupon Codes
Tagged: coupon discount
- This topic has 6 replies, 2 voices, and was last updated 9 years, 10 months ago by Anonymous.
-
AuthorPosts
-
Thu 19 Feb 2015 at 09:04 #53516AnonymousInactive
I have a question if this would feasible. I experienced that people had trouble to put in the coupon code correctly and used a wrong code and did not get the discount.
I would like to achieve the following … if a coupon code is used that this not in a specific list and the field is NOT empty then I like to inform the booker that the discount code used is not valid. So that he has the option to correct the code or to empty the coupon field.
Any ideas?
Thu 19 Feb 2015 at 14:32 #53521FrankyKeymasterThat is not part of the code for giving discounts, but form evaluation. Look at the filter eme_eval_booking_form_post_filter
Thu 19 Feb 2015 at 15:34 #53524AnonymousInactiveHi Franky,
ok the filters are the solution but wouldn’t the eme_eval_booking_form_filter make more sense? As it is said: If defined, this function can do extra evaluations on the booking being done before it is recorded.
Thu 19 Feb 2015 at 17:01 #53526FrankyKeymasterEdit: no, the _post filter is better (the other filter creates the booker already, this one doesn’t)
Thu 19 Feb 2015 at 20:40 #53535AnonymousInactiveAnyway I’m not a programmer, I just can tweak code a bit but writing it from scratch is to hard by now. So I can’t do it on my own.
Fri 20 Feb 2015 at 00:11 #53542FrankyKeymasterIs the example not enough?
Fri 20 Feb 2015 at 08:34 #53551AnonymousInactive🙂 I’m sorry I don’t think so …
/** * Add a hook for the Events Made Easy system to allow for coupon codes */ 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']; } } // As long as the coupon code isn't empty, look for matches if ($coupon == "COUPON10" || $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); } /** print_r($answer); die; **/ return; }
is what I’m using for calculating the price and that works.
And now the new function and filter has to be developed – let me try:
add_filter('eme_eval_booking_filter','my_eme_coupon_code_check'); function my_eme_coupon_code_check($booking) { global $wpdb; $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME; // 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']; } } // Check if the coupon code isn't empty, and matches a valid coupon code if ($coupon != "COUPON10" || $coupon != "coupon10") { // coupon code is not valid do stuff - here I'm stuck } }
If you see the above code how close am I to a solution? 🙂
And how can the out put be written and made, if I like to say – please leave the coupon code field empty or correct the code?!Cheers
JK -
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.