get ticket ids

Home Forums Ticket Products Event Tickets Plus get ticket ids

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1166045
    Dan
    Participant

    I’m wondering how to get the associated ticket IDs from inside the loop, or with the ID of the current post. I haven’t been able to find this information in the post meta, though the price of the associated tickets is there.

    I’m using my own custom post type for the “events”.

    #1166179
    Nico
    Member

    Hi there Dan,

    Thanks for getting in touch! Interesting question here ๐Ÿ™‚

    Every ticket provider class (by ticket provider I mean RSVP tickets, WooCommerce tickets, etc) has a get_tickets function that accepts a ‘event_id’ (should work with custom post types) and returns the tickets associated with the given post. There’s also a get_tickets_ids function that might work for you. So for example if you want to get RSVP ticket associated with a given post ID you can use the following code:


    /* retrive RSVP tickets ids for a give post_id */
    if ( class_exists('Tribe__Tickets__RSVP') ) {

    $tickets_provider = Tribe__Tickets__RSVP::get_instance();

    $tickets_ids = $tickets_provider->get_tickets_ids ( $post_id );

    var_dump( $tickets_ids );
    }

    Please let me know if this helps you out or if you still need help with it, in which case please elaborate a bit more on what you are trying to achieve,
    Best,
    Nico

    #1166573
    Dan
    Participant

    Hey Nico, thanks for the response. It doesn’t appear what you sent is quite working though(I’ve made sure that $post_id contains the post ID). $tickets_ids is still an empty array. I know that there are tickets associated with the events as well, because if I just use the_content(), the tickets and buttons show up(just doesn’t work with ajax).

    I’m using woocommerce, and what I’m really looking to do is spit out a list of events, and inside those events(if it has tickets associated with it), generate a woocommerce add_to_cart shortcode with the IDs of the associated “products”.

    I don’t necessarily have to use the shortcode, but I need the ability to display the products on the right events, and add them to the cart via ajax, which the shortcode does(only it doesn’t present the quantity box).

    Hopefully this makes sense,

    Any help would be greatly appreciated.

    #1167183
    Nico
    Member

    Thanks for following up Dan!

    I guess the previous code sample wasn’t working because it was looking for RSVP tickets. I updated the code to look for WooCommerce tickets instead:

    /* Tribe, retrive Woo tickets ids for a give post_id - returns array or false if event tickets plus is not active */
    function tribe_get_woo_tickets_ids ( $post_id ) {

    // bail if event tickets plus is not active
    if ( !class_exists('Tribe__Tickets_Plus__Commerce__WooCommerce__Main') ) return false;

    $tickets_provider = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();

    return $tickets_provider->get_tickets_ids ( $post_id );

    }

    You can add the code above to your theme’s (or child theme’s) functions.php file and then call it in the template passing the correct post_id value. Tested locally and it’s working as expected when used with events post type, but it should work for any post type too.

    Give a try and let me know if it works now,
    Best,
    Nico

    #1167901
    Dan
    Participant

    Hey, thanks Nico – that worked great. I’ve seen a few other posts on here looking for a way to try to AJAX-ify things, so I figured I might as well post my solution below, though it might not be appropriate for everyone.

    I grabbed the product IDs with the above function, and manually generated quantity input and button that will add to the cart like below:

    <?php $myProducts = tribe_get_woo_tickets_ids($post_id); ?>
    <?php foreach($myProducts as $p): ?>
        <?php $_product = wc_get_product($p); ?>
        <input type="number" step="1" min="0" max="" name="quantity_<?= $p ?>" value="0" title="Qty" class="input-text qty custom-qty text" size="4" pattern="[0-9]*" inputmode="numeric">
        <span class="product-price"><?= $_product->get_price(); ?></span>
        <span class="product-name"><?= $_product->post->post_title; ?></span>
        <a rel="nofollow" href="/?add-to-cart=<?= $p ?>" data-quantity="0" data-product_id="<?= $p ?>" data-product_sku="" class="button product_type_simple add_to_cart_button ajax_add_to_cart added btn btn-primary hidden">Add to cart</a>
    <?php endforeach; ?>

    From there, I hid all the buttons I just created, and wrote a little JS to simulate a click with data-quantity updated on each of them that has a quantity in it’s sibling’s number input.

    It’s not the most ideal solution, but hopefully this helps someone out if they’re in desperate need to get an ajax solution with the events tickets plus plugin.

    Thanks for the support.

    #1168091
    Nico
    Member

    Stocked to hear you could work this out Dan! Thanks so much for sharing your code here, it will surely be useful for folks with similar needs ๐Ÿ™‚

    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 assist you.

    Have a great weekend,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘get ticket ids’ is closed to new replies.