• Resolved montgoger

    (@montgoger)


    Hi every one,

    First thanks so much for this plugin who answer to all my needs !

    Here my trouble. For each of my event I have 3 differents type room and for each room a different number of seat. So what i want it’s to initiate a discount code on the total and send in with a paypal button. I read many of the topics to install all of this, thanks for all your works, there is what i settle :

    Registration form format:

    <table class='eme_add_multibooking_form'>
    <tr><th scope='row'>Your Name*:</th><td>#_NAME</td></tr>
    <tr><th scope='row'>Your E-Mail*:</th><td>#_EMAIL</td></tr>
    <tr><th scope='row'>Your Phone number:</th><td>#_PHONE</td></tr>
    <tr><th scope='row'>Private deluxe room 650€</th><td>#_SEATS{1}</td></tr>
    <tr><th scope='row'>Double deluxe room 495€</th><td>#_SEATS{2}</td></tr>
    <tr><th scope='row'>Dormitory 395€</th><td>#_SEATS{3}</td></tr>
    <tr><th scope='row'>Coupon:</th><td>#_FIELD{01}</td>
    <tr><th scope='row'>Comment:</th><td>#_COMMENT</td></tr>
    #_CAPTCHAHTML[<tr><th scope='row'>Please fill in the code displayed here:</th><td>#_CAPTCHA</td></tr>]
    </table>
    #_SUBMIT

    functions.php (change with plugin My Custom Functions):

    /**
     * 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;
    	$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 = $answers[0]['answer'];
    
            $fullprice = $booking['price_id'];    
    
            // Place here your VOUCHER CODE and PERCENT for the event
            $voucher = montgogerNoel;
            $percent = 10;
    
    	// As long as the coupon code isn't empty, look for matches
    	if ($coupon != '') {
    
    			if ($coupon == $voucher) {
    
                                //$price = 11111;
                                  $price = $fullprice-($fullprice*($percent/100));
    
    	                        $fields['booking_price'] = $price;
    			        $where['booking_id'] = $booking['booking_id'];
    			        $wpdb->update($bookings_table, $fields, $where);
    		        }
    	}
    	return;
    }

    Payment form header format:

    <div>#_RESPSPACES{1} space Delux</div>
    <div>#_RESPSPACES{2} space Double</div>
    <div>#_RESPSPACES{3} space Dorm</div>
    
    <div>[eme_if tag='#ESC_FIELD{1}' ] Use of vouchure code: #_FIELD{1} [/eme_if] </div>
    
    <strong>Total due:  #_TOTALPRICE €</strong>

    Ok if i don’t put the coupon code verification everything work properly
    the http://chateaudemontgoger.com/events/8/yogaanddetox/#eme-rsvp-message give:
    1 space Delux
    2 space Double
    1 space Dorm
    Total due: 2035.00 €

    If I put the discount code, the system reconize the code but don’t make the operation propely and the #eme-rsvp-message page even don’t return any informations. If I put the line $price = 11111; for test the system return me the amount 11111 multiply by the total number of seat…

    Can you help me please…

    https://wordpress.org/plugins/events-made-easy/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author Franky

    (@liedekef)

    First of all, in this code:
    $fullprice = $booking['price_id'];
    ==> price_id is not a defined field for a booking, see http://www.e-dynamics.be/wordpress/?cat=41 for an example discount, I added an example to take into account multiseat and (possible) multiprice events too.

    Thread Starter montgoger

    (@montgoger)

    Thanks it’s already helping me !! I get already a lot of informations from your code. I put $booking['booking_price']; instead of $fullprice = $booking['price_id']; and #eme-rsvp-message page work better but don’t display the #_RESPSPACES{1} #_RESPSPACES{2} #_RESPSPACES{3}, but at least it’s not the most important i can work.

    When the system make the calculation it don’t give me the correct result and i can’t understand how he manage to make the calculation…

    For example for test I change the price the free different seats and put 200||100||50.
    In the case I pick 1 seat for the first categorie and 1 seat of the second categorie. The code $price = $fullprice-($fullprice*($percent/100)); should return me 300-(300*(10/100)=270 but always return me a result upper, in this special case he return 360…

    Help me please, I’m really out of idea and need a clever look on my code…

    Thread Starter montgoger

    (@montgoger)

    Ok I continue to search my mistake and I have one more clue :

    I’m still with 3 classes of prices 200||100||50.
    I change my code to test like this :

    function my_eme_coupons($booking) {
    	global $wpdb;
    	$bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    	$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 = $answers[0]['answer'];
    
            $fullprice = $booking['booking_price'];    
    
            // Place here your VOUCHER CODE and PERCENT for the event
            $voucher = montgogerNoel;
            $percent = 10;
    
    	// As long as the coupon code isn't empty, look for matches
    	if ($coupon != '') {
    
    			if ($coupon == $voucher) {
    
                                    $price = $fullprice+110;
                                  //$price = $fullprice-(($fullprice/100)*$percent);
                                  //$price = 11111;
                                  //$price = $fullprice-($fullprice*($percent/100));
    
    	                        $fields['booking_price'] = $price;
    			        $where['booking_id'] = $booking['booking_id'];
    			        $wpdb->update($bookings_table, $fields, $where);
    		        }
    	}
    	return;
    }

    I have a better understanding of what’s going on. The code in presence of the correct coupon always take the first class of price (200).

    After adding 110 $price = $fullprice+110;, the code send back 330 and multiply by the number of seats…

    So my question is how can I grab with $fullprice = $booking['booking_price']; (or something else) the total of my multiseats multiprice event ? And how can I sent back to the #eme-rsvp-message page the correct total ?

    Thx for the help 😉

    Plugin Author Franky

    (@liedekef)

    See my discount example for a multiprice event …

    Thread Starter montgoger

    (@montgoger)

    You are right it’s better to search by myself 😉
    I didn’t see before your code in this page so I change my code base on your…

    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'];
       $answers = eme_get_answers($booking_id);
       $coupon = $answers[0]['answer'];
    
       if (eme_is_event_multiseats($event_id)) {
          /* put in the event_id that needs processing, or leave out this line to process all events */
          $seats=eme_multi2aray($booking['booking_seats']); // $seats is now an array for the different seat categories defined
    
          // now check if we defined different prices per seat category
          if (eme_is_multi($booking['booking_price']))
              $fullprice=eme_multi2aray($booking['booking_price']);
          else
              $fullprice=$booking['booking_price'];
    
          // example: more than 2 seats in the first category and 3 seats in the second, then the price is 25 per seat in the first
          // and 15 in the second, or in the case all prices are the same for the different seat categories, set the new price to 30
            // Place here your VOUCHER CODE and PERCENT for the event
            $voucher = montgogerNoel;
            $percent = 10;
    
          if ($coupon != '') {
            if ($coupon == $voucher) {
                    if (eme_is_multi($booking['booking_price'])) {
                       $price = $fullprice-(($fullprice/100)*$percent);;
                    } else {
                    $price = $booking['booking_price'];
              }
            }
          }
    
          if (eme_is_multi($booking['booking_price']))
              $fields['booking_price'] = eme_array2multi($price);
          else
              $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }

    What’s this function in your code eme_multi2aray($booking['booking_price'] ? Because for the moment the code return me

    Call to undefined function eme_multi2aray()

    in the the #eme-rsvp-message page.

    I check eme_functions.php there is no function like this…

    I guess you are very occupy but thanks for your time…

    Plugin Author Franky

    (@liedekef)

    It’s a typo and should be eme_multi2array

    Thread Starter montgoger

    (@montgoger)

    Ok but even with eme_multi2array() it’s give me

    Call to undefined function eme_multi2array()

    . There is 2 eme_multi2array() to correct on the post http://www.e-dynamics.be/wordpress/?cat=41 .

    Plugin Author Franky

    (@liedekef)

    Argh … sorry again (that’ll teach me to post a howto without testing it)
    I updated the example. Should be eme_convert_multi2array and eme_convert_array2multi.
    Sorry about that.

    Thread Starter montgoger

    (@montgoger)

    Ok thanks so much, don’t be sorry i guess you have so much work and don’t have time to test everything… When my code will work I will be please to give you it and put it here than everyone could use it…

    For all my event my #eme-rsvp-message page return me this :

    Warning: join(): Invalid arguments passed in /homepages/40/d534356294/htdocs/app537866630/wp-content/plugins/events-made-easy/eme_rsvp.php on line 2842

    Fatal error: Call to undefined function get_blog_option() in /homepages/40/d534356294/htdocs/app537866630/wp-content/plugins/events-made-easy/eme_functions.php on line 69

    I guess it’s because you’re working ont the update, no ?

    Other problem i get

    Unsupported operand types in /homepages/40/d534356294/htdocs/app537866630/wp-content/plugins/my-custom-functions/my-custom-functions.php(107) : eval()’d code on line 30

    this is this line $price = $fullprice-(($fullprice/100)*$percent);

    Maybe because of the value return by the line upper ? $fullprice= eme_convert_multi2array($booking['booking_price']);

    Thread Starter montgoger

    (@montgoger)

    Apparently the error

    Warning: join(): Invalid arguments passed in /homepages/40/d534356294/htdocs/app537866630/wp-content/plugins/events-made-easy/eme_rsvp.php on line 2842

    is link to the function eme_convert_multi2array()

    Plugin Author Franky

    (@liedekef)

    What are you passing as an option to that function? Post your code again (based on my example).

    Thread Starter montgoger

    (@montgoger)

    There is my code based on your example:

    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'];
       $answers = eme_get_answers($booking_id);
       $coupon = $answers[0]['answer'];
    
       if (eme_is_event_multiseats($event_id)) {
          /* put in the event_id that needs processing, or leave out this line to process all events */
          $seats=eme_convert_multi2array($booking['booking_seats']); // $seats is now an array for the different seat categories defined
    
          // now check if we defined different prices per seat category
          if (eme_is_multi($booking['booking_price']))
              $fullprice=eme_convert_multi2array($booking['booking_price']);
                 else
                 $fullprice= $booking['booking_price'];
    
            // Place here your VOUCHER CODE and PERCENT for the event
            $voucher = montgogerNoel;
            $percent = 10;
    
          if ($coupon != '') {
            if ($coupon == $voucher) {
                  $price = $fullprice-(($fullprice/100)*$percent);
    
             }
          }
    
          if (eme_is_multi($booking['booking_price']))
              $fields['booking_price'] = eme_convert_array2multi($price);
              else
                $fields['booking_price'] = $price;
    
              $where['booking_id'] = $booking['booking_id'];
              $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }
    Plugin Author Franky

    (@liedekef)

    Your code is incorrect. First, if $voucher is a string, you should use quotes around the value.
    Second: since you have a multiprice event, $fullprice is an array, but you assign a single value to it, which later on messes up the eme_convert_array2multi function call.
    Do as I gave in my example, but based on your $voucher (I use $price for the original and new price):

    ....
          // now check if we defined different prices per seat category
          if (eme_is_multi($booking['booking_price']))
              $price=eme_convert_multi2array($booking['booking_price']);
          else
              $price=$booking['booking_price'];
    
          if ($coupon == $voucher) {
              if (eme_is_multi($booking['booking_price'])) {
                 $price[0] *= .9;  // or another calculation you want
                 $price[1] *= .9;
                 // do this for all prices, or just loop through the array
              } else {
                 $price = $price;
              }
          }
          if (eme_is_multi($booking['booking_price']))
              $fields['booking_price'] = eme_convert_array2multi($price);
          else
              $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }

    Also, like mentioned in my examples, don’t use $answers[0] for your checking, but use something like this:

    $coupon = "";
            $answers = eme_get_answers($booking_id);
            foreach ($answers as $answer) {
                if ($answer['field_name'] == "MY_FIELD_NAME") {
                   $coupon = $answer['answer'];
                }
            }

    Thread Starter montgoger

    (@montgoger)

    Waaahou Thanks, you help me a lot, that’s years I didn’t writed a code and I forget the basic 🙂

    I change my code as you told me and it’s already erase the error with the
    function eme_convert_multi2array();

    But I still have a error on the #eme-rsvp-message page :

    Fatal error: Call to undefined function get_blog_option() in /homepages/40/d534356294/htdocs/app537866630/wp-content/plugins/events-made-easy/eme_functions.php on line 69

    Apparently it’s link to the function get_blog_option() of eme_functions.php

    if ($contact_id < 1) {
    68	      if (function_exists('is_multisite') && is_multisite()) {
    69	         $thisblog = get_current_blog_id();
    70	         $userinfo = get_user_by('email', get_blog_option($thisblog, 'admin_email'));
    71	      } else {
    72	         $userinfo = get_user_by('email', get_option('admin_email'));

    I can’t see in my code where i call this function…

    My (our) new code :

    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'];
       $answers = eme_get_answers($booking_id);
       $coupon = "";
            $answers = eme_get_answers($booking_id);
            foreach ($answers as $answer) {
                if ($answers['field_name'] == "#_FIELD{1}") {
                   $coupon = $answers['answers'];
                }
            }
    
       if (eme_is_event_multiseats($event_id)) {
          /* put in the event_id that needs processing, or leave out this line to process all events */
          $seats=eme_convert_multi2array($booking['booking_seats']); // $seats is now an array for the different seat categories defined
    
          // now check if we defined different prices per seat category
          if (eme_is_multi($booking['booking_price']))
              $price=eme_convert_multi2array($booking['booking_price']);
          else
              $price=$booking['booking_price'];
    
            // Place here your VOUCHER CODE and PERCENT for the event
            $voucher = "montgogerNoel";
            $percent = 10;
    
          if ($coupon != '' && $coupon == $voucher) {
              if (eme_is_multi($booking['booking_price'])) {
                 $price[0] = $price[0]-(($price[0]/100)*$percent);
                 $price[1] = $price[1]-(($price[1]/100)*$percent);
                 $price[2] = $price[2]-(($price[2]/100)*$percent);
                 // do this for all prices, or just loop through the array
              } else {
                 $price = $price;
              }
          }
    
          if (eme_is_multi($booking['booking_price']))
              $fields['booking_price'] = eme_convert_array2multi($price);
          else
              $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }

    Plugin Author Franky

    (@liedekef)

    Could you try if this change fixes it for you:

    http://plugins.trac.wordpress.org/changeset/1028703

    Franky

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Discount code for multiprice and multiseat events’ is closed to new replies.