Thank you, again, for your help. I’ve spent more time playing in straight php and javascript than within the WP framework. Every once in a while, when the gate closes, I go a little crazy trying to figure out how to do things inside the gate.
As I said above, I got the discount ($10) action working before it occurred to me that I needed to validate the field in order to keep any incorrect or invalid codes from being completely ignored. I needed to take $10 off of the total of a multi-price(4 prices) form but I could only find examples for a percentage discount. The examples helped but getting to the total was challenging. I’m not sure I fully understand the elements in that code either (specifically, getting the $coupon variable & using the each individual product price instead of working with the total) but it seems to work.
FWIW, here’s the discount code action for the $10 discount:
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 = "";
foreach ($answers as $answer) {
if ($answer['field_name'] == "Coupon") {
$coupon = $answer['answer'];
}
}
// If coupon code used, apply the appropriate price change
/* COUPON CODE TO USE */
if ($coupon == "COUPON_CODE") {
/* TAKE OFF $10 */
$actualseats=$booking['booking_seats'];
$discount = 10;
//Covert Price to Array and take $10 from first price listed
$price=eme_convert_multi2array($booking['booking_price']);
$price[0] = $price[0]- ($discount/$actualseats);
$price[1] = $price[1]- ($discount/$actualseats);
$price[2] = $price[2]- ($discount/$actualseats);
$price[3] = $price[3]- ($discount/$actualseats);
//Convert Array back to price
$fields['booking_price'] = eme_convert_array2multi($price);
$where['booking_id'] = $booking['booking_id'];
$wpdb->update($bookings_table, $fields, $where);
}
return;
}