• Resolved montgoger

    (@montgoger)


    Hi again,

    This topic follow a precedent one:

    Discount code for multiprice and multiseat events

    Like you told me Franky I check your code

    http://www.e-dynamics.be/wordpress/?cat=41 and add a function check_coupon() to my function.php… For sure it’s doesn’t work and I miss something ;-). There is my problem, I don’t understand how your code return an information block the user and avoid him to get on the #eme-rsvp-message

    add_filter('eme_eval_booking_filter','check_coupon');
    function check_coupon($event) {
       $event_id=$event['event_id'];
    
    // Place here your VOUCHER CODE and PERCENT don't forget to declare in my_eme_discount_function()
       $vouchers = array(
                     'montgoger2noel',
                     'montgoger3easter',
                    );
    
    // Recovery of VOUCHER CODE
       $coupon = "";
       $answers = eme_get_answers($booking_id);
       foreach ($answers as $answer) {
           if ($answer['field_name'] == "#_FIELD{1}") {
              $coupon = $answer['answer'];
           }
       }
    
       foreach ($vouchers as $voucher) {
         if ($coupon !='' && $coupon<>$voucher) {
           // bad form entry
           return array(0=>1,1=>'Bad coupon code');
        }
       }
    }

    Thanks to the community to help me 🙂

    https://ww.wp.xz.cn/plugins/events-made-easy/

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

    (@liedekef)

    As said before: don’t use #_FIELD{1}, it will not work!!! Use a real field name.
    Also: your last foreach will always cause a “bad coupon code” to be returned. Try this:

    $coupon_found=0;
       foreach ($vouchers as $voucher) {
         if ($coupon !='' && $coupon==$voucher) {
            $coupon_found=1;
         }
       }
       if (!$coupon_found)
          return array(0,'Bad coupon code');
       else
          return array(1,'');

    Thread Starter montgoger

    (@montgoger)

    Everything is perfect 😀

    I know you told me this already but i have few reason to didn’t listen at you :
    #1 It’s work like this…

    #2 I wish i could change it, i search but i didn’t find how to get a “real field”. the name of my field is litteraly declare like this in Form fields. If you explain me exactly i will do it…

    #3 And because I’m As stubborn as a mule 😉

    Thanks Thanks thanks

    add_filter('eme_eval_booking_filter','check_coupon');
    function check_coupon($event) {
       $event_id=$event['event_id'];
    
    // Place here your VOUCHER CODE and PERCENT don't forget to declare in my_eme_discount_function()
       $vouchers = array(
                     'montgogernoel',
                     'montgoger3easter',
                    );
    
    // Recovery of VOUCHER CODE
       $coupon = "";
       $answers = eme_get_answers($booking_id);
       foreach ($answers as $answer) {
           if ($answer['field_name'] == "#_FIELD{1}") {
              $coupon = $answer['answer'];
           }
       }
    
       $coupon_found=0;
       foreach ($vouchers as $voucher) {
            if ($coupon !='' && $coupon==$voucher) {
                $coupon_found=1;
            }
       }
       if (!$coupon_found)
              return array(0,'Check your voucher code again please');
       else
              return array(1,'');
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Check discount code’ is closed to new replies.