Changing the order of tickets

If you are using Event Tickets Plus with WooCommerce and have more than one ticket for an event you may find that you would like to control the order in which the tickets appear - so that they are either ordered alphabetically by name or else in ascending order by price. This is actually fairly straightforward.

We are going to make use of template overrides, so if you have not already done so please do take the time to review our Themer's Guide.

🔔 Note:  The method shown here works with the Classic Editor. Block Editor Ticket Order can be modified by dragging and dropping the tickets within the block, as well as dragging and dropping the entire ticket block anywhere within the editor.  Customizing the code to sort will likely not work in the Ticket Block.

 

First, we need to add a short snippet to your theme's functions.php file:

function tribe_wootickets_custom_sort($p, $q) {
        if ($p->name < $q->name) return -1;
        if ($p->name > $q->name) return 1;
        return 0;
}

Then we need to override the /event-tickets-plus/src/views/wootickets/tickets.php template (by creating a custom copy, ie themes/YOUR_THEME/tribe-events/wootickets/tickets.php) and add a single line of code. First, locate the following line of code (typically found on line 7):

ob_start();

Add an additional line of code right after it:

usort($tickets, 'tribe_wootickets_custom_sort');

With that done you should find that tickets are ordered alphabetically. If you want to order them by price you can, alternatively, change the snippet that you added to your 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;
}