Adding to price
WordPress Event Management, Calendars & Registration › Forums › General Question › Adding to price
This topic contains 16 replies, has 2 voices, and was last updated by Karl Lettenström 8 years, 11 months ago.
-
AuthorPosts
-
March 15, 2016 at 1:51 pm #21917
Hey
I work on some usage that a customer has ordered, and hoping i will be abel to solve it with EO. This is how the customer wants it:
Person adding a course and select what to learn from a select-box. They can to this up to 10 times. This shall than be added to the price with discounts based on how many courses they did choose.
So, what i try to figure out, and still haven’t been able succeeded is a way to add a sum of money to the booking. Is this possible, and if so, would you mind pointing me in that direction?
/Karl
Karl Lettenström
March 15, 2016 at 4:05 pm #21923Hi Karl,
Yes, this is possible. Event Organiser Pro uses JavaScript filters (these are like the standard WordPress filters, but ported to JavaScript).
Here’s an example of a plug-in making use of the checkout total. In this case, it is adding a percentage of the booking total (but it demonstrates how the code works): https://github.com/stephenharris/Event-Organiser-VAT/blob/02c7aeda3e881ceb082ce60f83576394481b7be4/assets/js/vat.js#L23-L45
Stephen Harris
March 17, 2016 at 9:14 am #21946Thanks Stephen! Will try to get my stuff working based on that!
Will report back on how it all turned out, just if anyone is interested! 😀Karl Lettenström
March 17, 2016 at 4:00 pm #21958Hey again!
I cant find a way to send “cart.total” to the database! As of for now i got this in my .js:
var registration_fee = eo_pro_course.course_regfee1;
var basic_fee = eo_pro_course.course_basfee1;
var course_amount = registration_fee+basic_fee;if (cart.quantity >= 1) { course_amount = course_amount+190; } if (cart.quantity >= 2) { course_amount = course_amount+250; } if (cart.quantity >= 3) { course_amount = course_amount+200; } if (cart.quantity >= 4) { course_amount = course_amount+150; } if (cart.quantity >= 5) { course_amount = course_amount+100; } if (cart.quantity >= 6) { course_amount = course_amount+50; } cart.total = course_amount;
This shows a correct amount for the viewer, but when i save it to db it shows as (registration_fee+basic_fee) + (190*number of tickets) in the admin view. (ticket price is set to 190).
I guess this will fall out bad to the end viewer all the way though, including the wrong price in email and such.I would also love to find out more about how to use the ticket-picker function, without using a ticket picker. Hehe. For example i’m using your Attendee Questions atm, but i would like to find out more about it, and even if there is a possibility adding a Attendee Questions by clicking a button, rather than adding a ticket. (it would be ok if the button added a ticket as well).
Like this:
“Add new course” > Attendee Questions-fields pops out and the user fills them in.
Then they click once more on the button and gets another sets of Attendee Questions.Oh, and btw:
I added ‘class’ => “col-md-4”, to $attendee_fields, and it adds the class in the select/input, not the div thats is around it including all the labels and such. The other way around would make it easier styling it. 🙂Best regards, Karl
Karl Lettenström
March 17, 2016 at 5:09 pm #21959Yes, the JavaScript is for display purposes only. To alter the price you’ll need to add some server-side code.
The best way to do this is to store the items with the booking (see this snippet from the VAT extension which stores the value of the tax paid: https://github.com/stephenharris/Event-Organiser-VAT/blob/02c7aeda3e881ceb082ce60f83576394481b7be4/includes/vat.php#L80-L97).
Then you can use the filter
eventorganiser_get_booking_meta_booking_amount
to adjust the booking price. Again here’s the VAT extension doing that: https://github.com/stephenharris/Event-Organiser-VAT/blob/02c7aeda3e881ceb082ce60f83576394481b7be4/includes/vat.php#L100-L119It’s not clear how you including the additional data in what is
$_POST
-ed to the server. But you could probably check$_POST
in youreventorganiser_new_booking
callback. This isn’t ideal as that is a generic hook used when creating a booking, and you’d be making the assumption that$_POST
contains the relevant data – but there’s no guarantee of the context in which that hook is triggered. At the moment, it would a reasonable assumption, but that could change. I’d recommend doing some ‘sanity’ checking – i.e. check$_POST
contains what you’re after.I would also love to find out more about how to use the ticket-picker function, without using a ticket picker.
It’s possible to remove the ticket picker entirely. However, you would need to ensure that the same
$_POST
structure remained. I’d have to come back with more details on this.if there is a possibility adding a Attendee Questions by clicking a button, rather than adding a ticket
This would be possible, but you do need to add a ticket. Even if that is hidden entirely from the user. In fact, by increasing the cart quantity you are adding a ticket.
I added ‘class’ => “col-md-4″, to $attendee_fields
Could you give an example?
Stephen Harris
March 18, 2016 at 9:28 am #21968Oh yeah, i mean.. i do know that the JS only affects what you see, but what i ment was that even as i save the amount as meta, _eo_booking_booking_amount still contains a “false number” witch adds to the sum total while looking at the bookings in admin. But even if i could get a way to fetch the number of tickets and than manipulate that meta, there would still be showing the wrong sum.
I’d love to hear more about the ticket-picker-thingie!
And i’m also just fine with adding another ticket by clicking that button!
array('id' => 'pick asdf',
'type' => 'select',
'required' => true,
'options' => $asdf,
'label' => 'Pick one asdf:',
'description' => "desc...",
'class' => "col-md-4", )
gives this results:
<div id="eo-booking-form-element-wrap-pick asdf-eoc1" class="eo-booking-field eo-booking-form-element-select"> <label class="eo-booking-label" for="eo-booking-field-pick asdf-eoc1">
Pick one asdf:*
</label><select id="eo-booking-field-pick asdf-eoc1" name="eventorganiser[booking][pick asdf-eoc1]" class="col-md-4 eo-booking-field-select" style="">
</select><p> desc... </p>
</div>
Karl Lettenström
March 18, 2016 at 9:35 am #21969Wow, code-formatting went bad. Anyways, hope you can see what i mean.
If the class would get on the wrapping div instead it would also include the label, And that would make things much more easy. 🙂 And since you set the label text in the array, that was how i expected it to work.Maybe you could use ‘class’ => array(“class-for-wrap”, “class-for-type”, “class-for-label”), or something like that?
Karl Lettenström
March 19, 2016 at 9:01 pm #21981No worries, I’ll take a look.
Regarding the ticket picker, you can copy the file
templates / eo-ticket-picker.php
into your theme (or register a template location in another plug-in and use it there).
You can remove the parts you don’t need (e.g. quantity selection, or even the tickets themselves).Sorry, but could you elaborate on the following, I’m not sure I follow what you’re saying?
even as i save the amount as meta, _eo_booking_booking_amount still contains a false number witch adds to the sum total while looking at the bookings in admin. But even if i could get a way to fetch the number of tickets and than manipulate that meta, there would still be showing the wrong sum.
Stephen Harris
March 21, 2016 at 11:29 am #21996what is the .onchange you use for the ticket-picker? Or what do you use to know that an event happened? I would love to try out using a select instead, cuz that would give other positive features for me in this project as well! I could manipulate the .value of the input-field, but that does not add me the attendee-question-fieldsets.
And talking about these fieldsets. Is there any way for me to edit the “tmpl-attendee-questions”-sctipt template?Sorry, since english is not my native language i got some problems on how to explain the problem. 🙂
“false number” is misleading. Wrong is a better word.
In /edit.php?post_type=event&page=bookings i see the bookings. The price shown there is based on _eo_booking_course_amount plus the number of tickets * the ticket price.
I had to fill out a ticket price, even though i want to alter the price on every single new ticket added. So the JS prompting this value for the user shows the correct sum, but i cant show this value in the admin-table since that value is based on the actual price.Karl Lettenström
March 21, 2016 at 11:55 pm #22023Update about the “tmpl-attendee-questions”-script template:
i added the script to a template of my own and edited it there. Works fine. 🙂Karl Lettenström
March 22, 2016 at 3:12 pm #22034Sorry for hammering all these questions, mate, but i’m on a roll working with this, and keeps on hitting walls that i cant get by.
First of all, i thought my include_once( ‘tmpl-attendee-questions.php’ ) worked fine, but it turns out that it does not execute upon page-reaload when you post form and it returns due to some fields not being filled out correctly and so on.. Do you know if there is any way working around this?
I also changed the direction of how i work with this problem since my first question.
Back than i had 1 ticket that i used for all, and depending on how many tickets the user bought, they got a discount on the price. This did not turn out well since the price in admin (as i tried to talk about above) shows actual price, not modified. Same goes for the email.Now i use different tickets with different prices. This gives me a correct sum of money, and it also lets me use the discount-plugin and i don’t need to manipulate the data.
But, this does mean i need to build a select-function for the user. I don’t want them to see all the tickets and each ticket-picker, since they shall always only pick 1 ticket from 1 of the alternatives. Each ticket is a course, and the attendee can only book to attend 1 course. Thats why.
I got a select witch uses onchange to clear all the qty-inputs and adds +1 in the input equal the value in select. So far so good. This does not trigger the “total-row” neither the “attendee-questions” though (and maybe some other back-end-values?).
And that’s where i’m at right now, hoping you can point me in the right direction once again. 🙂Cheers,
KarlKarl Lettenström
March 22, 2016 at 7:50 pm #22035Hi Karl,
Apologies for having not responded to your earlier posts. So from what I gather you’re looking to replace the ticket list with number input with a select menu. Incidentally if you wanted to replace that number input with a radio button that is readily doable: http://wp-event-organiser.com/forums/topic/limit-one-ticket-per-person/
I shall follow up tomorrow with how to replace the ticket selection with a dropdown, once I’ve had chance to test it.
Stephen Harris
March 22, 2016 at 9:41 pm #22037Hey Stephan!
No worries, i know there is other stuff to do as well..! 😉Oh yeah, that is correct! And a radio button might be just good enough! Thanks, will look in to that!
Karl Lettenström
March 23, 2016 at 1:08 am #22039God damnit… There is no worse feeling than getting stuck at shit you think you should be abel to get pass.. haha 🙂
the radio buttons works nice. lovely. My next problem is that i still cant call the tmpl-attendee-questions. It gets called at i click an radio, but i need there to be different tmpl-attendee-questions for each ticket.
The tickets are like levels. The attendee choose a ticket from packade 1 through 6. If 6 is picked, i need there to be 6 attendee-questions showing. Numbers of attendee-questions should be the same as the picked radio.This is also why i try to use it as a template, since i need to modify the output!
Karl Lettenström
March 23, 2016 at 2:54 pm #22047Im lost when it comes to both Backbone and Underscores. Guessing that’s why i get stuck once again, as soon as i solve one step.
As for now, i think i will try to solve this using additional fields instead of attendee-questions since i cant get a grip of how to work it out. Any thoughts?
Karl Lettenström
-
AuthorPosts