Events Made Easy › Forums › How do I … › Discount that changes with number of seats
Tagged: discounts
- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by Franky.
-
AuthorPosts
-
Mon 25 Apr 2022 at 03:18 #64100AnonymousInactive
Hello,
I am a little flummoxed by this, at this point. I have tried unsuccessfully to create a code discount that changes the discount based on the number of seats to achieve a pricing structure for an event that is based on seats, couples, and tables. I don’t want to do it with three different options for seats because it will mess up the math since 2 and 8 will become 1 in the total, not to mention dividing the available seats into pools will also be logistically messy. I do know how to do this and did it successfully with a different “event,” (program ad space, half or whole page) but need a cleaner solution for this.
I have tried a sample discount from here https://www.e-dynamics.be/wordpress/category/documentation/17-discounts/ and been unsuccessful in getting it to do anything at all to the total, but I’m sure that’s because I’m tweaking the syntax incorrectly.
1 seat is $100, 2 are $175, and a table of 8 is $600, so the structure I need is 1=100, 2=175, 3=275, 4=350, 5=450, 6=525, 7=625, 8=600. Essentially, 1=-0, 2=-25, 3=-25, 4=-50, 5=-50, 6=-75, 7=-75, 8=-200. I might extend it to go all the way to 16=-400. I’m not a code shark but I can tweak things like that easily enough. The problem is that I simply cannot figure out the syntax on these discount functions.
Anyone genius enough to help me? I feel like this should be much easier than I’m making it.
Mon 25 Apr 2022 at 09:51 #64105AnonymousInactiveEventually I solved this on my own; well, God helped me 🙂
What I ended up doing that worked was a variation on one of the sample scripts that skipped the $coupon variable creation entirely and worked directly off the $booking variable with a sub-variable specified. You’ll see. It’s clumsy because it’s so specific, but it works like I need it to work, returning the correct price no matter how many seats are selected up to the limit of 16. (I did change my mind on 7 costing more than 8, too. It seemed silly.)
Also, I used Code Snippets from Code Snippets Pro to avoid having to edit the functions.php to add it. This is a much cleaner way to do it, from my point of view, and worked well for me. Hopefully it will prove reliable in the long run.
function my_eme_discount_function($booking) {
$calculated_discount=0;
$coupon=””;if ($booking[‘booking_seats’] == 2) {
$calculated_discount=25;
}
if ($booking[‘booking_seats’] == 3) {
$calculated_discount=25;
}
if ($booking[‘booking_seats’] == 4) {
$calculated_discount=50;
}
if ($booking[‘booking_seats’] == 5) {
$calculated_discount=50;
}
if ($booking[‘booking_seats’] == 6) {
$calculated_discount=75;
}
if ($booking[‘booking_seats’] == 7) {
$calculated_discount=125;
}
if ($booking[‘booking_seats’] == 8) {
$calculated_discount=200;
}
if ($booking[‘booking_seats’] == 9) {
$calculated_discount=200;
}
if ($booking[‘booking_seats’] == 10) {
$calculated_discount=225;
}
if ($booking[‘booking_seats’] == 11) {
$calculated_discount=225;
}
if ($booking[‘booking_seats’] == 12) {
$calculated_discount=250;
}
if ($booking[‘booking_seats’] == 13) {
$calculated_discount=250;
}
if ($booking[‘booking_seats’] == 14) {
$calculated_discount=275;
}
if ($booking[‘booking_seats’] == 15) {
$calculated_discount=325;
}
if ($booking[‘booking_seats’] == 16) {
$calculated_discount=400;
}
return $calculated_discount;
}
add_filter(’eme_discount_ball_discount’,’my_eme_discount_function’);Mon 25 Apr 2022 at 10:35 #64108FrankyKeymasterThat works, but this will me more “nice” to the eye:
function my_eme_discount_function($booking) { $calculated_discount=0; $coupon=""; switch ($booking['booking_seats'] ) { case 2: $calculated_discount = 25; break; case 3: $calculated_discount = 25; break; } return $calculated_discount; } add_filter('eme_discount_ball_discount','my_eme_discount_function');
Or even more simple (with direct return-statements):
function my_eme_discount_function($booking) { switch ($booking['booking_seats'] ) { case 2: return 25; case 3: return 25; } return 0; } add_filter('eme_discount_ball_discount','my_eme_discount_function');
Tue 26 Apr 2022 at 02:33 #64116AnonymousInactiveAnd that, boys and girls, is the difference between a desperate amateur and a professional. 🙂
Tue 26 Apr 2022 at 23:09 #64122FrankyKeymasterI wouldn’t call myself a professional, more a php-enthousiast 🙂 But in the end the case-statement internally gets converted to if-like structures anyway, so it is not that your code was wrong in any way.
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.