Events Made Easy › Forums › Bug fixed or feature request implemented › How do I reference a custom field int he php code
- This topic has 18 replies, 2 voices, and was last updated 11 years ago by
Franky.
-
AuthorPosts
-
Fri 18 Apr 2014 at 04:37 #51544
Anonymous
InactiveI 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!!
Fri 18 Apr 2014 at 04:38 #51545Anonymous
InactiveMy syntax is wrong on that last part, but hopefully you still get the idea.
Fri 18 Apr 2014 at 10:38 #51548Franky
KeymasterUse 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']);
Mon 21 Apr 2014 at 04:45 #51582Anonymous
Inactiveok, I can see the array, but my custom fields are not in it. Are these stored in a different place?
Mon 21 Apr 2014 at 13:44 #51583Franky
KeymasterHow 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.Mon 21 Apr 2014 at 14:44 #51585Anonymous
InactiveI 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?
Tue 22 Apr 2014 at 00:53 #51588Franky
KeymasterYes, please do read the link I provided above, it explains how to correctly add extra fields.
Tue 22 Apr 2014 at 05:06 #52004Anonymous
Inactiveok, 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.
Tue 22 Apr 2014 at 05:08 #52005Anonymous
Inactiveand 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.
Tue 22 Apr 2014 at 10:08 #52006Franky
KeymasterTry
$answers = eme_get_answers($booking['booking_id']); print_r($answers);
Tue 22 Apr 2014 at 14:36 #52015Anonymous
Inactivestill just get back
Array()
Tue 22 Apr 2014 at 15:09 #52017Franky
KeymasterList your code, and the output from print_r($booking) (you can obfuscate the parts you don’t want to be shown)
Wed 23 Apr 2014 at 04:24 #52031Anonymous
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.
Wed 23 Apr 2014 at 10:08 #52033Franky
KeymasterOk, 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);
Thu 24 Apr 2014 at 04:20 #52052Anonymous
InactiveArray([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()
Thu 24 Apr 2014 at 10:45 #52054Franky
KeymasterThis is not logical at all …
Can you mail the hook-code to me at liedekef[at]telenet.be ?Thu 24 Apr 2014 at 15:55 #52058Franky
KeymasterOk, 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 …Thu 24 Apr 2014 at 19:07 #52060Franky
KeymasterFixed with this:
http://plugins.trac.wordpress.org/changeset/901839Fri 25 Apr 2014 at 10:08 #52061Franky
KeymasterAnd as second part: https://plugins.trac.wordpress.org/changeset/902032/
-
AuthorPosts
- The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.