Home › Forums › Ticket Products › Event Tickets Plus › Order tickets by menu_order, how to extend woocommerce ticket.
- This topic has 3 replies, 2 voices, and was last updated 8 years, 9 months ago by Nico.
-
AuthorPosts
-
July 20, 2015 at 10:03 am #987894MarceloParticipant
Hello.
I need order my tickets by menu_order and not added order. But I don’t want change do core of Woocommerce Tickets.
I do this, but doesn’t work. Can help me?
remove_action( 'plugins_loaded', 'wootickets_init' ); add_action('plugins_loaded', 'Extended_wootickets_init'); function Extended_wootickets_init() { tribe_init_woo_tickets_autoloading(); if ( ! wootickets_should_run() || ! class_exists( 'Tribe__Events__Tickets__Tickets' ) ) { $langpath = trailingslashit( basename( dirname( __FILE__ ) ) ) . 'lang/'; load_plugin_textdomain( 'tribe-wootickets', false, $langpath ); add_action( 'admin_notices', 'tribe_wootickets_show_fail_message' ); return; } new Tribe__Events__Tickets__Woo__PUE( __FILE__ ); Extended__Events__Tickets__Woo__Main::init(); } class ADMT__Events__Tickets__Woo__Main extends Tribe__Events__Tickets__Woo__Main { public function get_tickets_ids( $event_id ) { if ( is_object( $event_id ) ) $event_id = $event_id->ID; $query = new WP_Query( array( 'post_type' => 'product', 'meta_key' => $this->event_key, 'meta_value' => $event_id, 'meta_compare' => '=', 'posts_per_page' => - 1, 'fields' => 'ids', 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC', ) ); return $query->posts; } }
Thanks,
Marcelo- This topic was modified 8 years, 9 months ago by Marcelo.
July 20, 2015 at 1:06 pm #988075NicoMemberHi Marcelo,
Thanks for reaching out to us and welcome to our support forums ๐
I crafted a simpler snippet to achieve the same. First add the following code to your functions.php file:
function get_reordered_tickets ( $event_id ) {
$woo_instance = Tribe__Events__Tickets__Woo__Main::get_instance();
$event_key = $woo_instance->event_key;$query = new WP_Query( array( 'post_type' => 'product',
'meta_key' => $event_key,
'meta_value' => $event_id,
'meta_compare' => '=',
'posts_per_page' => - 1,
'fields' => 'ids',
'post_status' => 'publish',
'orderby' => 'menu_order',
'order' => 'ASC', ) );$ticket_ids = $query->posts;
if ( ! $ticket_ids )
return array();$tickets = array();
foreach ( $ticket_ids as $post ) {
$tickets[] = $woo_instance->get_ticket( $event_id, $post );
}return $tickets;
}
Now you need to create a template override for the tickets form:
– Inside your theme folder create the following folder structure ‘tribe-events/wootickets/’.
– Copy the file ‘tickets.php’ from ‘wp-content/plugins/wootickets/src/views/wootickets/’ to the just created folder in your theme.
– Edit the file and add the following line bellow ‘ob_start();’ :
$tickets = get_reordered_tickets ( $post->ID );
Please try that out and let me know if it works for you,
Best,
NicoJuly 22, 2015 at 10:11 am #988927MarceloParticipantHi Nico,
It works!! Thanks for your help.
We could suggest how to improve the “The Events Calendar Pro”, allow add and change the order of tickets for the event page in wp-admin.
Regards,
MarceloJuly 22, 2015 at 10:33 am #988977NicoMemberHey Marcelo,
Glad to hear it worked as expected ๐
Surely that would make a great feature for our product! You are welcome to suggest it via our UserVoice Page if you like.
Iโll go ahead and close out this thread, but if you need help with anything else please donโt hesitate to create a new one and we will be happy to help.
Best of luck with your project,
Nico -
AuthorPosts
- The topic ‘Order tickets by menu_order, how to extend woocommerce ticket.’ is closed to new replies.