Created
April 29, 2016 19:34
-
-
Save liath/3e20e630abc5850c59595b9b17b5b9a0 to your computer and use it in GitHub Desktop.
Make Modern Tribe Events Calendar sort Woo Tickets by their product order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use this guide to order your tickets (products) in WooCommerce: http://www.endocreative.com/customize-product-sorting-woocommerce/ | |
// Basically, you'll just Woocommerce->Products, click sort, then drag items around to get the order right. | |
// Per https://theeventscalendar.com/knowledgebase/changing-the-order-of-tickets/ | |
// Add this just after the "ob_start();" line in your_theme/tribe-events/wootickets/tickets.php | |
// tribe_wootickets_sort($tickets); | |
// Add the rest of this to your functions.php | |
// Sort alphabetical | |
function tribe_wootickets_sort_alpha($p, $q) { | |
if ($p->name < $q->name) return -1; | |
if ($p->name > $q->name) return 1; | |
return 0; | |
} | |
// If menu_order is specified, use it else sort alphabetical | |
function tribe_wootickets_sort(&$tickets) { | |
$are_tickets_ordered = false; | |
$real_tickets = array(); | |
foreach($tickets as $ticket) { | |
$real = get_post($ticket->ID); | |
$real_tickets[$ticket->ID] = $real; | |
if ($real->menu_order != 0) $are_tickets_ordered = true; | |
} | |
if ($are_tickets_ordered) { | |
$final = array(); | |
foreach ($tickets as $ticket) { | |
$final[$real_tickets[$ticket->ID]->menu_order][] = $ticket; | |
} | |
foreach ($final as $slot) usort($slot, 'tribe_wootickets_sort_alpha'); | |
ksort($final); | |
$tickets = array(); | |
array_walk_recursive($final, function ($current) use (&$tickets) { | |
$tickets[] = $current; | |
}); | |
} else { | |
usort($tickets, 'tribe_wootickets_sort_alpha'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment