how to echo message if there is no ticket for event

Home Forums Calendar Products Community Events how to echo message if there is no ticket for event

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1026553
    marc-andre
    Participant

    when a event have a ticket, the ticket.php file generate it, it’s fine….
    but when the event dont have ticket, it dont event go into ticket.php

    what i need,like to add is a message like : the is no ticket availible for this event yet !

    where i can do it ?

    • This topic was modified 10 years, 5 months ago by marc-andre. Reason: title missing part
    #1026975
    George
    Participant

    Hey @Marc-andre,

    It seems like the best solution here is to just write out the text in the bottom of your event description if there are no tickets there. Maybe in some bold text just write something like “No tickets for sale yet!” or something.

    Do you agree? If not, can you please explain all the things you mean about how the tickets.php file is involved at all here? As you mentioned, if there are no tickets then this file will not be called, so you can’t change that behavior at this time.

    Thanks,
    George

    #1027069
    marc-andre
    Participant

    I whant the message “no ticket availible yet” when no ticket are created, but when the ticket are create for this event, i show them (the ticket) not the text

    #1027079
    George
    Participant

    Hey @Marc-andre,

    You will be in the event editor to begin with to add tickets – so why not just remove the “no tickets yet” text in your event description when you add tickets?

    I’m just genuinely curious here – not trying to force you to do something if you don’t want it!

    However, if you for some reason just don’t want to do this manual work, then doing this automatically will take writing custom code. We can not help with writing custom code, so I’m just trying to help simplify things.

    Thanks for your patience here! Let me know what you think 😀

    — George

    #1027083
    marc-andre
    Participant

    i understand what you are asking me to do, but from my point of view, it must be simple and foolproof… I like the “keep it stupid” way to do. I alread know how to rewrite the ticket.php file, but when there is no ticket, where i should put the code ?

    #1027092
    George
    Participant

    Hey @marc-andre,

    Okay, if you really want to add some text like this then do not make a customization to a file. Instead, just use the action tribe_events_single_event_after_the_content. You can test this out first just to see how it works on your site with the following code:


    add_action( 'tribe_events_single_event_after_the_content', 'tribe_support_1026553' );

    function tribe_support_1026553() {
    printf( '

    %s

    ', 'There are no tickets!' );
    }

    From there, build it up into some code that detects whether any tickets exist and such. That’s where the code gets a bit complex, and since we do not support custom features like this you will have to take the reins on coding that yourself.

    Best of luck with your customizations!

    George

    #1027793
    marc-andre
    Participant

    Oh thanks… but to check if there is tickets, what function or var can be query ?

    #1028333
    George
    Participant

    What I wrote above still unfortunately replies here:

    From there, build it up into some code that detects whether any tickets exist and such. That’s where the code gets a bit complex, and since we do not support custom features like this you will have to take the reins on coding that yourself.

    So you will ultimately have to build out this customization and that functionality.

    In closing, however, here is some code that might work for you. I have not tested this, and you will need to play around to build what you want exactly, but this is a function that should get all the IDs of tickets attached to an event. If there are none, then it will return false:


    function example_if_has_tickets() {

    $post_id = get_the_ID();

    if ( Tribe__Events__Main::POSTTYPE !== get_post_type( $post_id ) )
    return false;

    $Woo__Tickets = Tribe__Events__Tickets__Woo__Main::get_instance();
    $ticket_ids = $Woo__Tickets->get_tickets_ids( $post_id );

    $num_tickets = count( $ticket_ids );

    if ( $num_tickets && 0 < intval( $num_tickets ) )
    return true;

    return false;
    }

    So you can use this in a loop somewhere, for example, like this:


    if ( example_if_has_tickets() ) {
    // There are tickets, so run that code.
    } else {
    // There are NO tickets, so run that code
    }

    I hope that helps you get started – it’s an idea and example. You will need to take the reins on the rest of your customizations, but if you want to hire professional help then one thing that might help further is a list of some highly-reviewed developers that we have here: http://m.tri.be/18k1

    Cheers!
    George

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘how to echo message if there is no ticket for event’ is closed to new replies.