Add custom field data to specific ticket meta after checkout

Home Forums Ticket Products Event Tickets Plus Add custom field data to specific ticket meta after checkout

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1000746
    Erico
    Participant

    I’ve implemented the code found at http://stackoverflow.com/questions/22824303/woocommerce-get-quantity-of-specific-items-in-cart-on-checkout-page/31864150#31864150 with a few modifications for my needs.

    The problem is, I’m not sure how to attach the input field data I’ve collected to specific tickets. I’ve been reading around and noticed some different actions such as wootickets_generate_ticket_attendee, but I’m not really sure how to utilize this with my own custom function. So for instance:

    add_action(‘wootickets_generate_ticket_attendee’, ‘wt_generate_tickets’);

    function wt_generate_tickets(){
    // What code goes here to let me save custom meta to tickets
    }

    This is assuming that this is a possibility. Any help would be greatly appreciated.

    #1000889
    George
    Participant

    Hey Erico,

    I’m glad you found a code solution elsewhere online, but we unfortunately do not offer support for custom code.

    That’s a disclaimer that I have to put out there front-and-center, just to set expectations reasonably, but with that all being said I can at least offer some general advice here 🙂

    It seems like the main point of your question is this:

    I’m not sure how to attach the input field data I’ve collected to specific tickets.

    I’ll leave the collection-of-data aspects of this to you, but in regards to adding that data to specific tickets, there are essentially two steps to go through:

    1. Get the WooCommerce Product ID
    2. Use WordPress’ update_post_meta() function with that Product ID to add your input data to the metadata of the ticket.

    For step 1, there are many ways of doing this. If you look at the code you shared, for example, you can see one case in the wt_count_attendees() function that should serve as a good example for you. The code in question is this:


    global $woocommerce;

    if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
    foreach ( $woocommerce->cart->get_cart() as $item_id => $values ) {
    $_product = $values['data'];
    }
    }

    I modified the code just to “highlight” the parts we need…

    But look in the real code and note what happens with this $_product variable – it’s used like a “post” object in the code and has its ID called, like this:

    $_product->id

    So that’s one way of doing this. Get that product ID and then proceed to step 2, and just add metadata to it with update_post_meta(), like this:


    update_post_meta( $_product->id, '_example_field_for_Ericos_data', $the_input_value_to_save );

    And that should be good.

    I’m sorry to let you down if you were hoping for line-by-line coding examples or troubleshooting; we unfortunately cannot provide any support for custom code. Hopefully the information I’ve shared here does at least help a little bit, though!

    Best of luck with your customizations,
    George

    #1000918
    Erico
    Participant

    Hey, thanks so much for this help. I understand you can’t offer support for custom code. What I’d really like to understand is how your plugin works, and what you’ve provided helps a lot.

    So to make sure I understand correctly, if someone were to buy multiple tickets in one checkout process, each ticket would have a unique product id? Is there a way to access the ticket ids after someone has checked out and the cart is empty? That was the problem I was running into was getting the ids for each ticket.

    Thanks again for the help!

    #1001639
    George
    Participant

    Thanks for the kind reply Erico, I appreciate your respecting of our custom-code limitations!

    As for your next questions:

    if someone were to buy multiple tickets in one checkout process, each ticket would have a unique product id?

    Great question! There are a few things at work during a WooCommerce order with WooTickets.

    Each different ticket would indeed have a different ID. So, for example, if you have tickets like “Movie: Adult Full Price” and “Movie: Senior Discount”, then these two separate tickets indeed have different IDs. If a person buys one of each, there will be different ticket IDs.

    However, if you have one person who buys two of the same type of ticket – to continue our example, one person buying two “Adult Full Price” tickets – then there’d only be one ticket ID.

    Is there a way to access the ticket ids after someone has checked out and the cart is empty?

    Yes, and this is a great way to see what I’m talking about above in action.

    You have a few different options. If you want to explore all the possible ways of getting this data, your best bet is to dive into the WooTickets code itself and just read through how various things work, try removing things and var_dump()-ing things along the way and then make test purchases to see how specific code blocks actually effect things on the front-end of your site, and so on.

    The simplest way of getting this info, though, is to find the Order ID of the order you want more information on. This is accessible by viewing “Orders” in your wp-admin. When you see the labels like “Order #221”, then 221 is the Order ID for that Order.

    You’d get info like this:


    $order = wc_get_order( 221 );

    // Dump info about the whole order.
    var_dump( $order );

    // Dump info just about the items in the order.
    $items = $order->get_items();
    var_dump( $items );

    That should hopefully be a good start on things.

    If you’d like to get tickets by the Event ID, and not by WooCommerce order, than you can do so like this – assuming that $event_id is indeed an ID for an event that has tickets:


    $tickets = Tribe__Events__Tickets__Tickets::get_all_event_tickets( $event_id );

    var_dump( $tickets );

    Cheers!
    George

    #1006385
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Add custom field data to specific ticket meta after checkout’ is closed to new replies.