Display only tickets on sale

Home Forums Ticket Products Event Tickets Plus Display only tickets on sale

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1560391
    Robert
    Participant

    I created a child template for tickets.php under wootickets as per your instructions to link directly to the product from an event’s page.

    I typically have an early bird ticket special and regular tickets. Early bird stays up for a few weeks and may not sell out before the next ticket then shows.

    I would like it so that if either or of the tickets are sold out it does NOT show the ticket amount. Right now I have a sold out event, literally has zero tickets left, yet it’s still showing the link to the product and the price. I haven’t been able to find a solution in your docs. Maybe I have to check for if global stock is not less than zero then show?

    $count = 0;
    echo '<ul>';
    foreach ( $tickets as $ticket ) {
    	global $product;
    	$count++;
    	if ( class_exists( 'WC_Product_Simple' ) ) $product = new WC_Product_Simple( $ticket->ID );
    	else $product = new WC_Product( $ticket->ID );
    	$price = $product->get_price_html();
    	$link = '<a href="' . $product->get_permalink() . '">Buy now</a>';
    	
    		
    		if ( tribe_events_ticket_is_on_sale( $ticket ) ) {
    			
    
    	
    	echo "$price $link <br> $ticket->description  - [$ticket->stock] Available";
    	
    	} 
    	
    	
    	
    	
    }
    
    if ( 0 === $count )
    	echo '<li> There are no tickets available for this event </li>';
    echo '</ul>';
    

    I know you guys always say “we can’t help with customization” but this is a snippet of code directly from your docs so any help would be great, thanks.

    #1561196
    Victor
    Member

    Hi Robert!

    After reviewing your request this essentially looks like a custom development task and so is outside of our stated scope of support.

    With that being said, we’d love to help point you in the right direction.

    For your customization, you may want to take a look at the tribe_events_has_tickets() helper function available in https://github.com/moderntribe/event-tickets/blob/master/src/template-tags/tickets.php#L61 and also the other similar functions in that same file.

    If you’d prefer not to tackle this customization on your own, we may be able to assist you further. We do need to prioritize support requests from other customers at this time but I’ll certainly flag this with the team and – although we can’t make any promises – if we have time and space to come back and help, we’ll be happy to do so.  Please let us know if you’d like to go this route so that you can be added to this queue.

    In the meantime, if there is any more information you can share (including mocks) that will help us to better understand what you are seeking please do feel free to add them to this ticket.

    If you urgently need help with this, however, you may instead wish to consider working with a suitably skilled developer or designer who can offer the additional level of support you require.

    Thanks!
    Victor

    #1562339
    Robert
    Participant

    Thank you Victor!

    This is more or less what I came up with. It seems to work but just wanted to double check if this is the best way to do it. Thanks!

    <?
    
    $count = 0;
    echo '<ul>';
    foreach ( $tickets as $ticket ) {
    	global $product;
    	$count++;
    	if ( class_exists( 'WC_Product_Simple' ) ) $product = new WC_Product_Simple( $ticket->ID );
    	else $product = new WC_Product( $ticket->ID );
    	$price = $product->get_price_html();
    	$link = '<a href="' . $product->get_permalink() . '">Buy now</a>';
    	
    		if ( tribe_events_ticket_is_on_sale( $ticket ) ) {
            
    		$qunt= $ticket->stock;
    		
    		
    		if($qunt!='0')
    		{
    	     
    	echo "$price $link <br> $ticket->description  - [$ticket->stock] Available";
    		}
    		else 
    		{
    
    		echo '<p class="stockout">Out Of Stock</p>';
    		}
    	} 
    	
    }
    if ( 0 === $count )
    	echo '<li> There are no tickets available for this event </li>';
    echo '</ul>';
    
    
    #1562647
    Victor
    Member

    Hey Robert!

    It’s great you could come up with that.

    I don’t see any syntax or code errors and just made some tests and it seems to work on my end too. I’m not completely sure that it covers all scenarios, so I’d suggest you run some tests on your end just to make sure it works as you need to.

    You can setup a dev/staging site so you can test things out without disrupting the live site.

    Hope that helps! Is there anything else I can help you with? Let me know 🙂

    Best,
    Victor

    #1563125
    Robert
    Participant

    Thank you!

    In what scenarios might it not cover just out of curiosity?

    What I typically have is an early bird ticket that is scheduled for a certain time, then after that expires another ticket is scheduled for the same day the other one expired. So essentially two tickets but one is always hidden. Both use the global inventory.

    I just want to make sure I won’t run into any issues. I’m not sure of what problems would arise and don’t want to use the snippet if you think there are some cases where it will show as sold out when it’s not.

    Thanks!

    #1563633
    Victor
    Member

    Hi Robert,

    I’m not aware of a specific scenario where it wouldn’t work, I’t just I didn’t test every possible scenario on my end, but even if I did, it’s always suggested that you perform those tests yourself with your own site.

    This will allow you to ensure the code you are implementing works alongside all other components of your site, like your theme, other plugins, any other custom code you have and even your own site’s settings.

    I hope that makes sense. Let me know if any follow up question.

    Best,
    Victor

    #1563811
    Robert
    Participant

    Thanks I appreciate it! 🙂

    #1563972
    Victor
    Member

    You are very welcome Robert 🙂

    Since you marked this “Resolved” I’ll go ahead and close this thread now. But don’t hesitate to open a new topic if anything comes up and we’ll be happy to help.

    Cheers,
    Victor

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Display only tickets on sale’ is closed to new replies.