Plugin Author
Franky
(@liedekef)
It al depends on what you want: if you have #_SEATS{1} and #_SEATS{2}, it means you have multiple types of seats to sell. If the only goal is to provide a discount, you don’t need this.
Just create #_SEATS and use the code-type discount while checking the value of your custom field. I even added a working example for this @ https://www.e-dynamics.be/wordpress/discounts/ (read the chapter on ‘Discount filters (code type discount)’
Franky,
Thanks a lot for the quick reply. Yes, I thought I could do with a discount as a workaround, but the problem is that none of the examples I tried from the docs work. I add the code to my functions.php file, customize the details (i.e. the custom field name) but nothing happens, the total stays the same.
Unfortunately I’m testing it on a local environment and I’m not able to send you a link.
I know I’m probably missing something obvious…
Plugin Author
Franky
(@liedekef)
Did you create the discount with that name and type “code”? And did you assign that discount to your event?
Yes, I created a coupon with the same name and details of the example (if I understood the docs correctly: name “testdiscount2”, type “code”) and only changed the Custom field name and answer. Obviously I changed the details also in the functions.php. I also assigned the discount to the RSVP tab in the Event entry. See code below (“si” is the answer, “UNPLI” the fieldname)
function my_eme_discount_function($booking) {
$calculated_discount=0;
$coupon="";
// calculate your stuff based on the booking and answers arrays
// and return the discount. A starting example:
$answers=eme_get_booking_answers($booking['booking_id']);
foreach ($answers as $answer) {
if ($answer['field_name'] == "UNPLI") {
$coupon = $answer['answer'];
}
}
// now check $coupon for your wanted value and do the discount ($booking has all the booking info)
if ($coupon == "si") {
// return a total discount of 30%
$calculated_discount=$booking['event_price']*$booking['booking_seats']*.3;
}
return $calculated_discount;
}
add_filter('eme_discount_testdiscount2','my_eme_discount_function');
Nothing happens. The total updates but no discount is applied. I’m not very skilled in php, so – again – I may have missed something obvious.
Plugin Author
Franky
(@liedekef)
Code works just fine, but: no dynamic price updates with discount type code. So when you actually make the booking, it should be ok.
Edit: the next version will contain code so dynamic price updates work too for code-type discounts, and editing of the resulting discount will work too in the backend.
That will require a small change in the filter (one-line change), but that will be explained in the changelog.
-
This reply was modified 5 years, 7 months ago by Franky.
Hello Franky, I’ve just re-tested everything but when I make the booking there’s no discount, PayPal is always charging full price. I think I’ll use the 2 seats solution with no conditional for the moment. If you need me to do other tests I’ll be more than happy to help.
Plugin Author
Franky
(@liedekef)
Paypal usage is new info 🙂
Did you check the price in the EME backend? Is it correct there?
Ops, sorry, my fault, I should have made it clear that I was using PayPal.
Anyway: even in the EME backend I can see only the full price. No discount is applied.
Also the registration form is not storing the #_NAME field in the People and Change Registration table, but it is displaying it correctly in the confirmation email. I guess EME is storing this info in two different place? Maybe the same thing is happening with the discount?
Plugin Author
Franky
(@liedekef)
Well, I tried this code:
function my_eme_discount_function2($booking) {
$calculated_discount=0;
$coupon="";
// calculate your stuff based on the booking and answers arrays
// and return the discount. A starting example:
$answers=eme_get_booking_post_answers($booking);
foreach ($answers as $answer) {
if ($answer['field_name'] == "testveld") {
$coupon = $answer['answer'];
}
}
// now check $coupon for your wanted value and do the discount ($booking has all the booking info)
if ($coupon == "L") {
// return a total discount of 30%
$calculated_discount=$booking['event_price']*$booking['booking_seats']*.3;
}
return $calculated_discount;
}
add_filter('eme_discount_testdiscountcode2','my_eme_discount_function2');
And it works just fine … based on your problems, I’m guessing some small error is blocking you. You should check your webserver logfiles (and optionally your browser console) for possible errors. A good WP plugin that aids in debugging is query-monitor .