Posted: December 20, 2016 at 10:29 pm
|
I need to change the ability to buy tickets or not based on certain criteria about the user – this part i’ve done using PHP in the Event post and I’m able to set a value based on this. So – if i have a Boolean variable like $is_active_user and if it’s false, I want to eliminate the ticket section, how might i go about that? Easy to do with CSS, but not dynamically. Any ideas? |
Hi there, Are you looking to remove specific tickets or the whole ticket selector? |
|
|
Just want to prevent the user from continuing with the purchase somehow, not too fussed… even just hiding the purchase button would be fine. Hiding the whole ticket selector would be fine. |
You have a number of options available to you. The most secure would be to add a hook for the I am going to be submitting a PR here shortly that will add an official filter As for modding the front-end (not a singular solution, as you should *never* trust user-space), it seems you can hook the I wish there was a better filter, perhaps one that hooked in to Hope this helps you out… |
|
@westgate.community, Another approach would be to remove the submit button. Some example code follows:
|
|
Oh, my bad. I miss-read this to say “disable some tickets”. Didn’t understand “all”. Still, it may also be good to hook |
|
|
Thanks for all this. I’d prefer to not allow them to submit at all. Removing the submit button may be the simplest. Not too concerned about security, more about causing confusion. Without teaching me everything that I should already know…. It looks like i need to add a function (to which file?). Will every event then have to have the $is_active_user variable set? |
So you can add your code to a functions plugin or into your WordPress theme’s functions.php file. It should be possible to write the function so that every event will not need to have the $is_active_user variable set. May I ask are you setting the values for events using the post meta or something like that? |
|
|
I’m using S2 Member to validate that a user can access the event at all. The nuance I’m adding (using PHP in the post itself) is that we want to check that their membership doesn’t expire between the time they book the event, to when the event actually happens. I’m doing some simple math in PHP within the Event Post to check their expiry data against the event start date using espresso_event_date_obj() I’ve never used Post Meta much, so open to suggestions. |
Thanks for the clarification. I don’t think storing info in post meta would be part of the solution in this case. So you can probably move the PHP where you check their membership from the post itself into the custom function, you have access to the event object with that hook. |
|
|
OK. I don’t want to check membership for every event this way, so I’ll probably just leave it in the event itself for now. I’ll give this a shot a bit later. I’m a bit of a hack, so I appreciate your patience. |
|
Josh, This worked really well. I took your advice and pushed all my code into the function – certainly see the advantage. Two things are happening now: This is what I’m using now. I know it’s messy… 😉
|
|
OK. Making progress. I think i got the above sorted, but now realizing the add_action is causing the test to be run on every event. I only want to run the test when I call the function. How can i make that possible? I’m looking into adding the S2Member properties of the event itself to the conditions so if the page is restricted, we run the test…. Other ideas – I assume we can’t run add_action inside a function that we only call for some events? |
|
OK nailed this. Merry Christmas. My last request is how to remove the whole ticket selector instead of just the register button…. |
One way to remove the whole ticket selector is you add your code onto the Then you change the hook from Since the above hook does not have access to the $event object, you remove the $event parameter from your function, i.e.: Then in that last part where you have this: |
|
The support post ‘Dynamically changing ability to buy tickets’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.