I have no idea how tickets are sorted for WooCommerce tickets

Home Forums Ticket Products Event Tickets Plus I have no idea how tickets are sorted for WooCommerce tickets

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #967316
    Jon
    Participant

    Here is the page:

    Home

    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?

    #967426
    Geoff
    Member

    Hi 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!
    Geoff

    #967439
    Jon
    Participant

    OK, 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.

    -_-

    #967441
    Jon
    Participant

    Did I see somewhere that the code could be hacked so that the sorting functionality resident in WooCommerce could do the sorting?

    #967442
    Jon
    Participant

    Also, 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.

    #967452
    Geoff
    Member

    Hi 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!
    Geoff

    #967479
    Jon
    Participant

    Ah, 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?

    #967490
    Jon
    Participant

    OK, I figured it out, but the price at the top of the page still reflects the wrong ticket:

    Home

    That price at the top should say $12, not $20.

    #967819
    Geoff
    Member

    Oh 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!
    Geoff

    #967871
    Jon
    Participant

    This 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.php and placed it in theme\tribe-events\modules\meta\details.php.

    I replaced the php code as indicated.

    Now, nothing has changed. I’ve moved the details.php file up a level. I’ve copied over the list\single-event.php and day\single-event.php files 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:

    http://archfw.org/events/

    Home

    If only this had taken merely an hour.

    #967963
    Geoff
    Member

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

    #967989
    Jon
    Participant

    OK!

    Now it seems that everything is working correctly:

    http://archfw.org/events/

    Home

    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!

    #968129
    Geoff
    Member

    Sweet, 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

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘I have no idea how tickets are sorted for WooCommerce tickets’ is closed to new replies.