Events Made Easy Forums Bug fixed or feature request implemented How do I reference a custom field int he php code

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #51544
    Anonymous
    Inactive

    I am trying to write some code for an if statement about a custom field I created in my booking form. I was able to find this code sample to use as a starting point:

    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();
    
       $event_id = $booking['event_id'];
       //$discount_code = $booking['event_id'];
    
          //print 'EVENT ID='.$event_id .' Booking_id = '.$booking['booking_id'];
     	//print_r ($booking);
    
       if ($event_id == 12) {        /* put in the event_id that needs processing */
    
          $seats=$booking['booking_seats'];
          $price=$booking['booking_price'];
    
          // more than 2 seats, then the price is 25 per seat
          if ($seats> 1)
              $price = 25;
    
          $fields['booking_price'] = $price;
          $where['booking_id'] = $booking['booking_id'];
          $wpdb->update($bookings_table, $fields, $where);
       }
       return;
    }

    But instead of calling

    if ($event_id == 12)

    I want to say

    if ($my_new_field) == "valueOfField"

    How would I reference the value of my new field?

    Hopefully that make sense. Thanks!!

    #51545
    Anonymous
    Inactive

    My syntax is wrong on that last part, but hopefully you still get the idea.

    #51548
    Franky
    Keymaster

    Use this to get the answers for a booking in an array, so you can test it later on:

    $answers = eme_get_answers($booking['booking_id']);

    #51582
    Anonymous
    Inactive

    ok, I can see the array, but my custom fields are not in it. Are these stored in a different place?

    #51583
    Franky
    Keymaster

    How did you add the field to the booking form then?
    The only way custom fields can be added is via the method described here, all other fields you added via html itself will be ignored.

    #51585
    Anonymous
    Inactive

    I added it via the admin. But I think you are right, I just added it to the RSVP: Form Format. Is there somewhere else I need to add it?

    #51588
    Franky
    Keymaster

    Yes, please do read the link I provided above, it explains how to correctly add extra fields.

    #52004
    Anonymous
    Inactive

    ok, I was wrong. I did add these in the Form Fields view in the admin as well as adding it to the HTML of the form. I can see the values being captured in the CSV. Just not in the array.

    #52005
    Anonymous
    Inactive

    and this is the code I am using to print the array.

    print_r ($booking);

    The code you posted above isn’t showing me the values in the array.

    #52006
    Franky
    Keymaster

    Try

    $answers = eme_get_answers($booking['booking_id']);
    print_r($answers);
    #52015
    Anonymous
    Inactive

    still just get backArray()

    #52017
    Franky
    Keymaster

    List your code, and the output from print_r($booking) (you can obfuscate the parts you don’t want to be shown)

    #52031
    Anonymous
    Inactive
    	$answers = eme_get_answers($booking['booking_id']);
     	
    print_r ($answers);

    results in
    Array([event_id]=>7[person_id]=>7[wp_id]=>2[booking_seats]=>1[booking_seats_mp]=>[booking_price]=>370[booking_comment]=>test the comments[creation_date]=>xxxxxxx[modif_date]=>xxxx-xx-xx[creation_date_gmt]=>xxxxxx[modif_date_gmt]=>xxxxxxxx[booking_approved]=>0[booking_id]=>xx[transfer_nbr_be97]=>xxxxxxxxx

    obviously just replaced some numbers there, but hopefully this gives you the idea.

    #52033
    Franky
    Keymaster

    Ok, let’s start from the top:
    – if the CSV output shows it, it means it is in the output from
    $answers = eme_get_answers($booking[‘booking_id’]);
    – so: add the following code and show the output:

    
    print_r ($booking);
    $answers = eme_get_answers($booking['booking_id']);
    print_r ($answers);
    
    #52052
    Anonymous
    Inactive
    Array([event_id]=>7[person_id]=>7[wp_id]=>2[booking_seats]=>1[booking_seats_mp]=>[booking_price]=>370[booking_comment]=>comments[creation_date]=>xxxxxxx[modif_date]=>xxxx-xx-xx[creation_date_gmt]=>xxxxxx[modif_date_gmt]=>xxxxxxxx[booking_approved]=>0[booking_id]=>xx[transfer_nbr_be97]=>xxxxxxxxx)
    Array()
    #52054
    Franky
    Keymaster

    This is not logical at all …
    Can you mail the hook-code to me at liedekef[at]telenet.be ?

    #52058
    Franky
    Keymaster

    Ok, it’s in fact a bit of a bug:

    when inserting a booking, the booking info is inserted in the DB, then the action hook is called and only then the answers are inserted in the db …
    Of course the answers should be stored before the action hook is called, so you have all info at your disposal.
    I’ll create a fix for this this evening, moving to bugs …

    #52060
    Franky
    Keymaster
    #52061
    Franky
    Keymaster
Viewing 19 posts - 1 through 19 (of 19 total)
  • The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.
Scroll to Top