Restrict Ticket Sales to WordPress Members only

Home Forums Ticket Products Event Tickets Plus Restrict Ticket Sales to WordPress Members only

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #1110227
    Iain
    Participant

    Hi.

    How do I restrict Ticket Sales only to WordPress Members only?

    Regards
    Iain

    #1110463
    Geoff
    Member

    Hi 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.php

    I 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!
    Geoff

    #1110642
    Iain
    Participant

    Hey 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
    Iain

    #1110701
    Iain
    Participant

    Also 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
    Iain

    #1110713
    Geoff
    Member

    Hey 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!
    Geoff

    #1110724
    Iain
    Participant

    Cool.
    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
    Iain

    #1110771
    Iain
    Participant

    Hi 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
    Iain

    #1110963
    Geoff
    Member

    Hey 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,
    Geoff

    #1111186
    Iain
    Participant

    Hi 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
    Iain

    #1111430
    Geoff
    Member

    Nice! 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 else condition 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!
    Geoff

    #1111723
    Iain
    Participant

    Hi 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
    Iain

    #1111760
    Iain
    Participant

    OK, 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
    Iain

    #1111924
    Iain
    Participant

    Hi 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/wootickets

    Is this the right thing to do?

    #1112266
    Geoff
    Member

    Nice 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!
    Geoff

    #1112334
    Iain
    Participant

    Hi 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

Viewing 15 posts - 1 through 15 (of 26 total)
  • The topic ‘Restrict Ticket Sales to WordPress Members only’ is closed to new replies.