Home › Forums › Ticket Products › Event Tickets Plus › I have no idea how tickets are sorted for WooCommerce tickets
- This topic has 12 replies, 2 voices, and was last updated 10 years, 11 months ago by
Geoff.
-
AuthorPosts
-
June 4, 2015 at 1:39 pm #967316
Jon
ParticipantHere is the page:
No matter how I change the date or title of the tickets, the $20 ticket shows up as the default at the top. How are these being sorted?
June 5, 2015 at 7:55 am #967426Geoff
MemberHi there, Jon!
Sorry for the confusion here, I know it can be tricky. Tickets are displayed in the order they were created, which is likely why you keep seeing the same ticket stuck at the top.
The ability to reorder tickets manually has been suggested on our feature request forum (but needs more votes). In the meantime, here are some examples of how to reorder the tickets in a number of ways, such as alphabetically or by price.
Will those work for you? Please let me know. 🙂
Cheers!
GeoffJune 5, 2015 at 8:31 am #967439Jon
ParticipantOK, so I have an hour or so of hacking in front of me to simply change the order of this list.
Oh my stars I was afraid you’d say that.
-_-
June 5, 2015 at 8:32 am #967441Jon
ParticipantDid I see somewhere that the code could be hacked so that the sorting functionality resident in WooCommerce could do the sorting?
June 5, 2015 at 8:33 am #967442Jon
ParticipantAlso, to be clear, the tickets are shown in OPPOSITE order of when they are created. Change the publication date all you want, that sort is set.
June 5, 2015 at 9:00 am #967452Geoff
MemberHi Jon, thanks for following up!
Shoot, I hope I didn’t give you the impression that this requires a hack or a ton of work. Quite the contrary, actually. In fact, I’d be happy to outline the steps for you here:
- Make a copy of the tickets.php file. It is located in /plugins/wootickets/views/wootickets/tickets.php
- Make a new folder in your theme directory called tribe-events
- Make a new folder in that one called wootickets
- Drop your copied tickets.php file in that last folder
Now that the file is in your theme, we can override it. In this case, find this line towards the top:
ob_start();
…and paste this as the very next line:
usort($tickets, 'tribe_wootickets_custom_sort');
You’re all done there! The very last thing to do is paste this into your theme’s functions.php file:
function tribe_wootickets_custom_sort($p, $q) { if ($p->price < $q->price) return -1; if ($p->price > $q->price) return 1; return 0; }I hope this helps breaks it down into an easier process for you! Please feel free to let me know if you hit an questions along the way and I’d be happy to help. 🙂
Cheers!
GeoffJune 5, 2015 at 11:04 am #967479Jon
ParticipantAh, I’m being grouchy because this seems to be one of those things that you’d think would be core.
OK, I went through the steps and I see no change. How do I troubleshoot?
June 5, 2015 at 12:04 pm #967490Jon
ParticipantOK, I figured it out, but the price at the top of the page still reflects the wrong ticket:
That price at the top should say $12, not $20.
June 8, 2015 at 7:49 am #967819Geoff
MemberOh nice! I’m glad that snippet helped sort the price in the ticket form–awesome job putting that together. 🙂
The price at the top of the page takes the maximum price by default, so having $20 up there is correct. You could change this to show a price range instead. I know you’re not a fan of custom code, but the steps outlined in this thread are solid and will make that happen.
Cheers!
GeoffJune 8, 2015 at 9:02 am #967871Jon
ParticipantThis is quite frustrating.
I’ve visited this page: https://theeventscalendar.com/support/forums/topic/higest-ticket-price-shown-in-event-page/
I have copy-pasted the code into the theme functions.php file.
I have copies the details.php file from
the-events-calendar\views\modules\meta\details.phpand placed it intheme\tribe-events\modules\meta\details.php.I replaced the php code as indicated.
Now, nothing has changed. I’ve moved the
details.phpfile up a level. I’ve copied over thelist\single-event.phpandday\single-event.phpfiles and I’m utterly clueless as to what need to be changed there.Despite everything, I’m still stuck with $20 at the top of these pages:
If only this had taken merely an hour.
June 8, 2015 at 2:49 pm #967963Geoff
MemberHi Jon,
Sorry for the frustration here but I definitely appreciate your patience as well.
Let’s try to flesh those steps out a little more:
1) You already have a tribe-events folder in your theme. Add a copy of single-event.php to that folder, which is located at /plugins/the-events-calendar/views/single-event.php
2) Change this line:
<span class="tribe-events-cost"><?php echo tribe_get_cost( null, true ) ?></span>…to this:
<span class="tribe-events-cost"><?php echo esc_html( get_tribe_woocommerce_tickets_price_range() ); ?></span>2)Â You already have a file in your theme at tribe-events/list/single-event.php. Change this line:
<span><?php echo tribe_get_cost( null, true ); ?></span>…to this:
<span class="tribe-events-cost"><?php echo esc_html( get_tribe_woocommerce_tickets_price_range() ); ?></span>3) Add this snippet to your theme’s functions.php file.
[php]
function get_tribe_woocommerce_tickets_price_range() {
$event_id = get_the_ID();
$ticket_prices_array = $ticket_range = ”;$args = array(
‘post_type’ => ‘product’,
‘meta_key’ => ‘_tribe_wooticket_for_event’,
‘meta_value’ => $event_id
);$ticket_prices = new WP_Query( $args );
if ( $ticket_prices->have_posts() ) :
while ( $ticket_prices->have_posts() ) : $ticket_prices->the_post();
$product_id = get_the_ID();
$ticket_prices_array[] = get_post_meta( $product_id, ‘_price’, true );
endwhile;
endif;
wp_reset_postdata();
$ticket_prices_array_count = count($ticket_prices_array);
$minprice = min($ticket_prices_array);
$maxprice = max($ticket_prices_array);if ( $ticket_prices_array_count ) {
if ( $minprice != 0 && is_numeric( str_replace( array( ‘,’, ‘.’ ), ”, $minprice ) ) ) {
$ticket_range .= tribe_format_currency( $minprice );
} elseif ( $minprice == 0 ) {
$ticket_range .= __( "Free", ‘tribe-events-calendar’ );
}
if ( $ticket_prices_array_count > 1 && $minprice != $maxprice && is_numeric( str_replace( array( ‘,’, ‘.’ ), ”, $maxprice ) ) ) {
$ticket_range .= __( " to ", ‘tribe-events-calendar’ ) . tribe_format_currency( $maxprice );
}}
return $ticket_range;
}
[/php]I was able to get the full price range when following these steps. Let me know if you’re still hitting any issues here and I’d be happy to help.
Cheers,
GeoffJune 8, 2015 at 4:10 pm #967989Jon
ParticipantOK!
Now it seems that everything is working correctly:
And I tested it on a different event, to make sure the sorting was working for a new event, also.
Man, I tell ya. Maybe the directions on your site just aren’t as clear as you guys think they are or something. I really appreciate all of the help through this, but it’d be great if directions for stuff like this went into the knowledgebase. Thanks!
June 9, 2015 at 7:44 am #968129Geoff
MemberSweet, thanks Jon! Nice work on this and thanks for your patience throughout. I’m so glad everything is worked out.
A Knowledgebase article on price ranges is a good idea and I’ll definitely bring it up with the team–I can definitely see how that would be helpful rather than having to dig through the forums.
Thanks again for reaching out! Feel free to hit us bak up if any other questions pop up and we’d be happy to help. 🙂
Cheers,
Geoff -
AuthorPosts
- The topic ‘I have no idea how tickets are sorted for WooCommerce tickets’ is closed to new replies.
