Order tickets by menu_order, how to extend woocommerce ticket.

Home Forums Ticket Products Event Tickets Plus Order tickets by menu_order, how to extend woocommerce ticket.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #987894
    Marcelo
    Participant

    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.
    #988075
    Nico
    Member

    Hi 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,
    Nico

    #988927
    Marcelo
    Participant

    Hi 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,
    Marcelo

    #988977
    Nico
    Member

    Hey 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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Order tickets by menu_order, how to extend woocommerce ticket.’ is closed to new replies.