volume discount
-
I am trying to implement a sort of volume discount on a multiprice event.
I teach kids, and if there is more than one child attending overall, I want to reduce the price by 500. Note this is not for each additional child, just once.
When all the kids are the same price, then I just adjust the overall price to reflect the discount,
$price = (($seats * $price) - 500)/$seats;
as shown below based on the example in the faq for discounts. The relevant part is the else part of the
if ($found == 1&&eme_is_multi($booking['booking_price'])) {
section below.But now I want to charge older kids a different price. With a multiprice, I dont know how to adjust the price. What I want is if the total number of seats is more than one, regardless of the ages, to somehow take 500 off the price. If there is only one child, that child should be charged teh appropriate price. I can’t use the formula above because there are different seats and prices involved. There may be just one child for each price. I don’t care about the individual prices so much as the total price.
I suppose there might be a way to use discounts, but I don’t know how, and I dont want parents to have to enter “coupons”. I just want to automatically take the discount. It would be nice to be able to show them in my RSVP form that they had x kids at price 1 x kids at price 2 and there was a discount taken, but just as long as I can tell them the final price.
NOTE: I don’t need at this point to send the revised amounts to a payment vendor, as people pay at the door, but the question does come up.
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']; //not sure why this is here, but somehow I needed it. header("X-XSS-Protection: 0"); //initialize find loop. This is a loop that can be ignored now, but might be used later. $found=0; // This section used to search for only a specific category to apply discount to. // Presently the actual check for a particular category is disabled. all categories work. // First, collect the event categories for this event $event_c = eme_get_event_categories($event_id); $event_ct = $event_c[0]; foreach($event_c as $x => $x_value) { //disabled check, all categories //if ($x_value['category_id'] == 3) { $found=1; //echo "We found it!!! ".$found."<br />"; //}; //echo "<br>"; }; //echo "did we find it?".$found."<br />"; if ($found == 1&&eme_is_multi($booking['booking_price'])) { // echo "this is a multiprice event".eme_is_multi($booking['booking_price']); // THIS IS WHERE I WANT TO PUT MY NEW CODE. } else { // echo "this is a single price event".eme_is_multi($booking['booking_price']); $seats=$booking['booking_seats']; $price=$booking['booking_price']; // more than 2 seats, then the price is reduced 500 if ($seats> 1) { $price = (($seats * $price) - 500)/$seats; } $fields['booking_price'] = $price; $where['booking_id'] = $booking['booking_id']; $wpdb->update($bookings_table, $fields, $where); } return; }
- The topic ‘volume discount’ is closed to new replies.