Woo Event Ticket Cart – Separate Tickets / Show Attendee Meta

Home Forums Ticket Products Event Tickets Plus Woo Event Ticket Cart – Separate Tickets / Show Attendee Meta

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #1187010
    slny311
    Participant

    When having meta data attached to each tickets for example ( name, email ), when adding these tickets to the cart.

    It just feels like bad user experience having them remove all the tickets if they entered something wrong and wants to make changes to 1 of the ticket.

    Also if they changed their mind and want to remove one ticket there is no way of knowing which ticket they are removing.

    #1187366
    slny311
    Participant

    wrong topic
    This isn’t resolved I miss-clicked the button

    • This reply was modified 7 years, 6 months ago by slny311.
    • This reply was modified 7 years, 6 months ago by slny311.
    #1187716
    Geoff
    Member

    Hey Steven,

    That’s excellent feedback.

    I am afraid that we do not have a workaround, though I believe that would be possible to accomplish with custom development — most likely with an override of WooCommerce’s cart template. The trick (and admittedly a tough one) would be to alter the WooCommerce query for products in the cart so that it displays all instances of a product rather than grouping them together in batches with quantity.

    Ultimately, the change will have to come on the WooCommerce side of things since Event Tickets Plus is merely using the default WooCommerce functionality rather than it’s own thing.

    Sorry I don’t have a concrete solution here, but does this at least help answer your question? Please let me know.

    Thanks,
    Geoff

    #1187718
    slny311
    Participant

    That is Fine but is there a way to get those Form meta data from the current cart?
    (in cart page and not in cart page)

    I need to grab the name and email info from those grouped tickets.
    I will tackle on separating the woo-commerce cart if I am able to get all the info I need.

    Currently I am having trouble finding where you guys keep those Meta data attached to each individual tickets, since they aren’t an item data meta in cart?

    #1187823
    Geoff
    Member

    Hi Steven,

    Yeah, getting the ticket meta is admittedly a tedious tasks. It’s one of the few areas of the plugin that does not have a public function to easily fetch and echo the data and that is indeed something we have ticketed in our system to improve.

    For the time being, I do have a working example of the ticket meta being called that you can use as a blueprint for your work:

    $meta_fields = Tribe__Tickets_Plus__Main::instance()->meta()->get_meta_fields_by_ticket( $ticket['product_id'] );<

    $meta_data = get_post_meta( $ticket['qr_ticket_id'], Tribe__Tickets_Plus__Meta::META_KEY, true );

    if ( empty( $meta_fields ) || empty( $meta_data ) ) {
    return;
    }

    foreach ( $meta_fields as $field ) {

    if ( 'checkbox' === $field->type && isset( $field->extra['options'] ) ) {
    $values = array();

    foreach ( $field->extra['options'] as $option ) {
    $key = $field->slug . '_' . sanitize_title( $option );

    if ( isset( $meta_data[ $key ] ) ) {
    $values[] = $meta_data[ $key ];
    }
    }

    $value = implode( ', ', $values );

    } elseif ( isset( $meta_data[ $field->slug ] ) ) {
    $value = $meta_data[ $field->slug ];
    } else {
    continue;
    }

    // can use these vars to echo, etc:
    // $field->slug
    // $field->label
    // $value
    }

    I hope this helps!

    Geoff

    #1189305
    slny311
    Participant

    Hi

    The above code looks for order that has already been purchased?
    What I need is to get the Metadata when they are still sitting in the cart, so I can modify how the cart page works and maybe make them into different variations of the same product so that each tickets are independent.

    Shouldn’t I be accessing the session data in the cart to get these meta? how do I look for that in this plugin?

    My data below v
    $items = $this->get_cart_for_session();
    $_product = $values[‘data’]->post;
    $values[‘product_id’]<- this is the id I am using to pull these data

    $meta_fields
    Tribe__Tickets_Plus__Meta__Field__Text Object ( [type] => text [id] => [label] => Member Org [slug] => member-org [required] => [ticket_id] => 3500 [extra] => Array ( ) [field_type_name] => Array ( [checkbox] => Checkbox [radio] => Radio [select] => Dropdown [text] => Text ) [post] => WP_Post Object ( [ID] => 1054 [post_author] => 545 [post_date] => 2016-02-17 11:51:26 [post_date_gmt] => 2016-02-17 16:51:26 [post_content] => the content here [post_title] => LIREG Golf and Tennis Outing [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => lireg-golf-and-tennis-tournament [to_ping] => [pinged] => [post_modified] => 2016-10-24 17:21:35 [post_modified_gmt] => 2016-10-24 21:21:35 [post_content_filtered] => [post_parent] => 0 [guid] => http://5cf.563.mwp.accessdomain.com/?post_type=tribe_events&p=1054 [menu_order] => 0 [post_type] => tribe_events [post_mime_type] => [comment_count] => 0 [filter] => raw ) )
    $meta_data
    Array ( [0] => Array ( [type] => text [required] => [label] => Member Name [slug] => member-name [extra] => Array ( ) ) [1] => Array ( [type] => text [required] => [label] => Member Org [slug] => member-org [extra] => Array ( ) ) [2] => Array ( [type] => text [required] => [label] => Member Email [slug] => member-email [extra] => Array ( ) ) )

    • This reply was modified 7 years, 5 months ago by slny311.
    #1189352
    Geoff
    Member

    Hi @slny311,

    The snippet I provided is not intended to be the exact code you will use, but as an example for how the ticket meta can be fetched and then displayed where you would like, in this case, the WooCommerce cart template.

    The method for fetching ticket meta should not rely on whether the session of the cart, but more on whether there are tickets in the cart. Once a ticket is in there, calling it’s meta data is really what you’re looking to do and the snippet I provided is an example of how to get those fields.

    Cheers!
    Geoff

    #1189357
    slny311
    Participant

    can you explain how you got your variable $ticket array?
    I cannot find any $ticket->qr_ticket_id in all of the data i pulled from cart.

    so when I use those function with the cart’s item product id, I get an empty array back.

    #1189919
    Brook
    Participant

    Hello again slny311,

    Geoff asked me to chime in here since I have done a decent amount of work surrounding Attendee Meta.

    When a customer order advances beyond the pending payment phase Event Tickets Plus generates a WP Post for each attendee. For WooCommerce attendees this post has the post type: tribe_wooticket The ID of this post is the “qr_ticket_id” that is referred to in the above code. Since this will not get generated until after the cart has submitted its data and progressed further along the purchasing process, this post will not exist and won’t be useful to you inside the cart page.

    The meta data itself gets submitted to the cart page inside the $_POST[‘tribe-tickets-meta’] key. So you could read it from there. If the order progresses Woo will store this meta data along with any other Woo meta data in the wp_woocommerce_order_itemmeta table. So you can read/alter it in there until such time as the payment processing phase and the tribe_wooticket post gets created. At that point the data will be stored in the tribe_wooticket post meta and can be queried using the code Geoff shared.

    It just feels like bad user experience having them remove all the tickets if they entered something wrong and wants to make changes to 1 of the ticket.

    I completely agree. We have been discussing some possible options to address this. If you would like to vote on this issue please checkout this feature request/user story. Currently my preferred solution would be to mimic how Woo product variations, and split each ticket up into its own item in the cart complete with the details (meta info) attached to it. This will take a little bit of time to implement, but I think it would be pretty slick.

    Please let us know if you have any further questions. We do want to help as much as we can with customizations like this, but of course when it comes providing/inspecting code we have to leave a certain amount of exploration up to you or your developer. Cheers!

    – Brook

    #1189928
    slny311
    Participant

    Update:

    The Code posted above only works when user already checked out with their order.

    From the code located in:
    \event-tickets-plus\src\Tribe\meta\Storage.php
    public function get_meta_data_for( $id )

    I see that the data is stored in here
    $transient = self::TRANSIENT_PREFIX . $_COOKIE[ self::HASH_COOKIE_KEY ];
    but I am having trouble trying to obtain this data in my version of the code.

    $transient = ‘tribe_tickets_meta_’ . $_COOKIE[‘tribe-event-tickets-plus-meta-hash’];
    $data = get_transient( $transient );
    print_r($data);

    #1189938
    slny311
    Participant

    Hi Brook, I haven’t read your reply yet. let me dig deeper into your reply.

    -edit
    Ok I have read your reply and yes that is correct.
    To get this to work I would need to read the Cart meta after forms are being submitted and Before They move to the checkout or payment portion.

    So the first step I need is being able to read those data stored in the cookie?

    • This reply was modified 7 years, 5 months ago by slny311.
    #1190145
    Brook
    Participant

    So the first step I need is being able to read those data stored in the cookie?

    If your code is running after that transient is generated, yes! That would be the ideal way of doing it.

    – Brook

    #1190265
    slny311
    Participant

    How come I get an empty array even though I see the cookie already got created ( webdev tool cookie inspector )

    #1190447
    Geoff
    Member

    Hi @siny311

    I am not actually sure why the array is coming back empty. I checked with Brook and he is not sure as well. But keep playing around with it, you are on the right track. I just tried manually editing the transient in the database before clicking “Proceed to checkout” and it worked wonders. So you are certainly going in the right direction.

    Cheers,
    Geoff

    #1191135
    slny311
    Participant

    I got the function to work but it seems like the plugin has one big flaw when it comes to adding tickets over the maximum stock number.
    Example:
    Stock left = 4;
    Cart contains 2 tickets;
    User go to event to add 4 more tickets -> add tickets to cart;

    (backend function doesn’t add the metadata for any tickets that goes over the limit)
    resulting in transient data not matching the woocommerce cart quality.
    below is the URL and Code

    Event Link

    
    $transient = 'tribe_tickets_meta_' . $_COOKIE['tribe-event-tickets-plus-meta-hash'];
    $data = get_transient( $transient );
    if ( empty( $data ) || is_scalar( $data ) ) {
    $data = array();
    }
    if($ticketevent){
    								echo '<ul class="cart-ticket-list">';
    								foreach($data[$product_id] as $ticketkey=>$singledata){
    									echo '<li>';
    									foreach($singledata as $key=>$singlemeta){
    										echo ($key == 'member-name' ? $singlemeta : '' );
    										echo ($key == 'first-name' ? $singlemeta .' ' : '' );
    										echo ($key == 'last-name' ? $singlemeta : '' );
    									}
    									echo '<a href="#" onClick="metaRemove(' . $product_id . ',' . $ticketkey . ',this);return false;"><small>remove</small></a>';
    									echo '</li>';
    								}
    								echo '</ul>';
    							}
    <script>
    function metaRemove(product_id, ticketkey,e){
    							$(e).html('<small class="blue">Pending</small>');
    							$.ajax({
    							  url: se_ajax_url + '?action=ticket_meta_ajax&pid=' + product_id + '&tid=' + ticketkey
    							}).done(function(data) {
    							  var curval = $('.pid' + product_id + ' input.qty').val();
    							  $('.pid' + product_id + ' input.qty').val(curval-1);
    							   $('.pid' + product_id + ' input.qty').change();
    							   $(".button[name=update_cart]").click();
    							});
    						}
    				</script>
    function ticket_meta_ajax() {
    	$ticket_meta_expire_time = 86400;
    	$transient = 'tribe_tickets_meta_' . $_COOKIE['tribe-event-tickets-plus-meta-hash'];
    	$data = get_transient( $transient );
    	$product_id = sanitize_text_field($_REQUEST['pid']);
    	$ticket_key = sanitize_text_field($_REQUEST['tid']);
    	$temparray = $data[$product_id];
    	array_splice($temparray,$ticket_key,1);
    	$data[$product_id] = $temparray;
    	set_transient( $transient, $data, $ticket_meta_expire_time );
    	die;
    }
    • This reply was modified 7 years, 5 months ago by slny311.
Viewing 15 posts - 1 through 15 (of 16 total)
  • The topic ‘Woo Event Ticket Cart – Separate Tickets / Show Attendee Meta’ is closed to new replies.