Home › Forums › Ticket Products › Event Tickets Plus › Restrict Ticket Sales to WordPress Members only
- This topic has 25 replies, 2 voices, and was last updated 9 years, 11 months ago by
Geoff.
-
AuthorPosts
-
May 3, 2016 at 3:58 pm #1110227
Iain
ParticipantHi.
How do I restrict Ticket Sales only to WordPress Members only?
Regards
IainMay 4, 2016 at 7:48 am #1110463Geoff
MemberHi Lain — nice to see you again and hope all is well!
Good question. While there is no setting for that in the plugin, you could achieve the same effect by overriding the tickets.php template and wrapping the ticket form in the is_user_logged_in() function to display it only for logged in visitors.
This WordPress Codex article is a great place to start, with examples of how that works.
The calendar template you are looking is:
/wp-content/plugins/event-tickets-plus/src/views/wootickets/tickets.phpI would also suggest looking at our Themer’s Guide for more details on how template overrides work, if you haven’t seen it already — super helpful!
Does this make sense and will it work for you? Please let me know. 🙂
Cheers!
GeoffMay 4, 2016 at 12:02 pm #1110642Iain
ParticipantHey Geoff.
I will definitely look at what you have suggested.
But before I do, I just want to make sure that I understand.
By overriding the tickets.php template and wrapping the ticket form in the “is_user_logged_in()” function to display it only for logged in visitors, the Event will still be visible, but Tickets won’t be available unless you are logged in?
Is that correct?
Cheers
IainMay 4, 2016 at 3:21 pm #1110701Iain
ParticipantAlso Geoff, I am using a Child Theme to stop any customizations like altered Template Files being lost when there is a Theme upgrade.
That being the case, where would I put the edited template file?Would it be this:
/wp-content/themes/child-theme/event-tickets-plus/src/views/wootickets/tickets.php
or somewhere else?
Cheers
IainMay 4, 2016 at 4:05 pm #1110713Geoff
MemberHey Lain!
By overriding the tickets.php template and wrapping the ticket form in the “is_user_logged_in()” function to display it only for logged in visitors, the Event will still be visible, but Tickets won’t be available unless you are logged in?
That is correct: the event itself will be visible, but the ability to purchase tickets will only display for those who are logged into WordPress.
/wp-content/themes/child-theme/event-tickets-plus/src/views/wootickets/tickets.php
Just a slight difference:
/wp-content/themes/child-theme/tribe-events/tickets/wootickets/tickets.php
Cheers!
GeoffMay 4, 2016 at 4:17 pm #1110724Iain
ParticipantCool.
OK, now I just have see whether I am actually smart enough to work out how to do this.
If I am not, are there people you can recommend that I can pay to do it?
I am assuming that this is wayyyyy out of the scope of the support you can supply right?Cheers
IainMay 4, 2016 at 5:28 pm #1110771Iain
ParticipantHi Geoff.
So I have been reading the WordPress Codex link you gave me and it seems to me that the function you mentioned is supposed to go in the functions.php file, and then make reference to what you want to do.
So it’s confused me because I thought I was editing the tickets.php file.
Any comment you have on this will be much appreciated.Cheers
IainMay 5, 2016 at 7:13 am #1110963Geoff
MemberHey Lain!
Here’s a better example in the article that shows the function being used directly in a template.
And, yes, we absolutely have folks we would happily recommend, should you need extra help. Check out this list and there are quite a few in there who I’m sure would love to work on this.
I went ahead and took a quick stab at it though. I haven’t thoroughly tested it, but hopefully this at least helps you get started!
Cheers,
GeoffMay 5, 2016 at 12:14 pm #1111186Iain
ParticipantHi Geoff.
You really helped me out there.
Your change to the template worked exactly as it should.
I am trying to analyse what you did, and I can see that you added <?php if ( is_user_logged_in() ) { ?> before the form action, and <?php } ?> after the form.
Is that all you did?
Now that I’ve seen this I understand perfectly, so thank you so much.Now I just have one more thing to discuss regarding this.
The edit to the template file only works when I do it in the core template file.
If I use the template in /wp-content/themes/child-theme/tribe-events/tickets/wootickets/tickets.php, it doesn’t work.Any thoughts?
Cheers
IainMay 6, 2016 at 7:15 am #1111430Geoff
MemberNice! So glad to hear that did the trick!
Yes, those are the only two edits I made to the file. If you wanted, you could add an
elsecondition in there to display a message for non-logged in users asking them to log in to purchase tickets, but now you get the basic idea.You know, I may have made an error in that file path. I rechecked the Themer’s Guide instructions and think this might be it instead:
/wp-content/themes/child-theme/tribe-events/wootickets/tickets.php
Does that work? I think it should but let me if not and we can try putting it in the parent theme instead as a test.
Thanks!
GeoffMay 6, 2016 at 2:58 pm #1111723Iain
ParticipantHi Geoff.
Great suggestion about the “else” condition.
I tried it but with no success.
I changed this:<?php if ( is_user_logged_in() ) { ?>
<form action=”<?php echo esc_url( $woocommerce->cart->get_cart_url() ) ?>” class=”cart” method=”post”to this:
<?php if ( is_user_logged_in() ) {
} else {
echo ‘To purchase a Ticket, you must be a Registered Member and be Logged In.’;
} ?>
<form action=”<?php echo esc_url( $woocommerce->cart->get_cart_url() ) ?>” class=”cart” method=”post”But all that happened was the page with the Event wouldn’t load.
I also tried adding the same thing at the end of the code area for want of a better word, with the same result.
Any suggestions?I actually checked the Themer’s Guide myself and just didn’t pick up on the extra folder inclusion.
But that part is all good now.Once again, thank you for all your assistance.
Cheers
IainMay 6, 2016 at 5:03 pm #1111760Iain
ParticipantOK, I just found a major problem 🙁
Using the modified ticket.php stops logged out visitors seeing the ticket.
But logged in visitors will see the following error message:Warning: include(/home/jetski/public_html/wp-content/themes/enfold-child/tribe-events/wootickets/../meta.php): failed to open stream: No such file or directory in /home/jetski/public_html/wp-content/themes/enfold-child/tribe-events/wootickets/tickets.php on line 94
Warning: include(): Failed opening ‘/home/jetski/public_html/wp-content/themes/enfold-child/tribe-events/wootickets/../meta.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/jetski/public_html/wp-content/themes/enfold-child/tribe-events/wootickets/tickets.php on line 94
Any ideas?
Cheers
IainMay 7, 2016 at 2:42 pm #1111924Iain
ParticipantHi Geoff.
I’ve fixed the error message by doing the following:
Changed line 94 in the tickets.php to read “include dirname( __FILE__ ) . ‘/meta.php’;”
and, copying the meta.php from /wp-content/plugins/event-tickets-plus/src/views to /wp-content/themes/enfold-child/tribe-events/wooticketsIs this the right thing to do?
May 9, 2016 at 8:32 am #1112266Geoff
MemberNice work, @lain!
That’s super odd. You shouldn’t have to copy the code from /meta.php into the template override. It sounds like the conditional else statement may have inadvertently removed the reference to meta.php when it’s a required file.
Still, it sounds like you were indeed able to fix the message doing just that.
I made a quick edit to the code I provided earlier to include that else statement but have not tested it. It is very possible that the meta.php file is needed regardless of whether the tickets are displayed or not, so my edits wouldn’t fix that. If that’s the case, it would take some more conditions to make sure everything is loading as it should and when it should.
Thanks!
GeoffMay 9, 2016 at 11:54 am #1112334Iain
ParticipantHi Geoff.
I just tried the code with the else statement, and it does the same thing, ie. the page just sits there trying to load but doesn’t proceed any further 🙁
Do you think it might be possible to modify an Event Template instead of the tickets.php to do the same thing?
Maybe the one that displays the Event Description.
If so, which template would you suggest?
I’ll have a crack at that instead.Cheers
Iain -
AuthorPosts
- The topic ‘Restrict Ticket Sales to WordPress Members only’ is closed to new replies.
