Events Made Easy Forums How do I … Split: Coupon Codes

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #53516
    Anonymous
    Inactive

    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?

    #53521
    Franky
    Keymaster

    That is not part of the code for giving discounts, but form evaluation. Look at the filter eme_eval_booking_form_post_filter

    #53524
    Anonymous
    Inactive

    Hi 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.

    #53526
    Franky
    Keymaster

    Edit: no, the _post filter is better (the other filter creates the booker already, this one doesn’t)

    #53535
    Anonymous
    Inactive

    Anyway 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.

    #53542
    Franky
    Keymaster

    Is the example not enough?

    #53551
    Anonymous
    Inactive

    🙂 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

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top