Delete ticket on the front-end

Home Forums Ticket Products Event Tickets Plus Delete ticket on the front-end

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1216477
    Bram Huisman
    Participant

    Hi there,

    My client wants to give customers who bought a ticket the power to delete themselfs from an event if they bought a ticket (we are using woocommerce + ticketplus to sell tickets). I am trying to build a function which enables this based on this function: https://github.com/moderntribe/event-tickets/blob/4.3/src/Tribe/Attendees_Table.php#L497-L498

    This function works on the back-end –> if you choose delete the attendee selected will be deleted. I build a function on my own to enable it on the front end:

    <div class="um-field">
    <?php
    $user_id = get_current_user_id();
    $current_user = wp_get_current_user();
    $customer_email = $current_user->user_email;

    $event_ids = $this->get_all_attendances($user_id, 0, strtotime('last year'));
    $future_events = [];
    $past_events = [];

    ?>
    <div class="um-account-heading uimob340-hide uimob500-hide"><i class="um-icon-ios-list"></i><?php _e('Mijn workshops', 'sage'); ?></div>

    <?php _e('Upcoming events', 'va073'); ?>

    <ul class="tribe-tickets attendance-list-old">
    <?php foreach ($event_ids as $id): ?>
    <?php $start_date = tribe_get_start_date($id, true, 'd F Y') . ' ' . __('om', 'va073') . ' ' . tribe_get_start_date($id, true, 'G:i') . ' ' . __('hour', 'va073');

    $current_time = current_time('timestamp');
    $event_date = strtotime(tribe_get_start_date($id, true, 'd-m-Y'));

    $tickets_provider = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    $tickets_ids = $tickets_provider->get_tickets($id);

    $bought_ticket = false;
    $refund = false;

    if (!$tickets_ids) continue;

    foreach ($tickets_ids as $ticket) {
    if (wc_customer_bought_product($customer_email, $user_id, $ticket->ID)): $bought_ticket = $ticket->ID; endif;
    if (!$bought_ticket): continue 2; endif;
    }

    $ticket = $tickets_provider->get_ticket($id, $bought_ticket);
    if($ticket->price != 0 && $ticket->regular_price != 0):
    $refund = true;
    endif;

    $attendees_provider = Tribe__Tickets__Tickets::get_event_attendees($id);
    $attendee_id = 0;

    foreach ($attendees_provider as $attendee) {
    if ($attendee['user_id'] == $user_id && !$attendee['order_warning']):
    $attendee_id = $attendee['attendee_id'];
    endif;
    }

    if ($event_date > $current_time): array_push($future_events, $id);
    ?>
    <li class="event-<?php echo esc_attr($id) ?>">

    <span><?php echo get_the_title($id); ?></span>
    <span>-</span>
    <?php if ($start_date): ?>
    <span class="datetime"><?php echo $start_date; ?></span>
    <?php endif; ?>
    </br>
    <?php if(!$refund): ?>
    "
    data-event="<?php echo $id; ?>" data-attendee="<?php echo $attendee_id; ?>" data-user="<?php echo $user_id; ?>">Uitschrijven

    <?php else: ?>
    "
    data-event="<?php echo $id; ?>" data-attendee="<?php echo $attendee_id; ?>">Terugbetaling aanvragen

    <?php endif; ?>
    "
    data-event="<?php echo $id; ?>" data-user="<?php echo $user_id ?>">Download ticket

    <?php endif;

    endforeach; ?>

    <?php if (empty($future_events)): ?>

    <li class="event-none">
    <?php esc_html_e('U heeft zichzelf niet aangemeld voor een van onze workshops', 'sage'); ?>

    <?php endif; ?>

    function delete_ticket()
    {
    check_ajax_referer('va073', 'security');

    $ticket = sanitize_text_field($_POST['ticket']);
    $event = sanitize_text_field($_POST['event']);

    $tickets_provider = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    $tickets_provider->delete_ticket($event, $ticket);

    echo $event;
    exit();
    }

    Everything works.. except one BIG thing.. if a user clicks delete on the front-end the WHOLE ticket gets deleted.. It only needs to delete this specific attendee.. not the whole ticket.

    I know you guys don’t provide support on customisation.. but my developer which made this code says that it’s not possible. I find this strange because at the back-end it works?

    Can you guys plsssssss help me!

    #1216480
    Bram Huisman
    Participant

    Above code is unreadable so this is a JSBIN: http://jsbin.com/mojedejepo/edit?html

    #1216920
    Brook
    Participant

    Howdy Bram,

    I would love to help you with this as best I’m able. But I have a quick question for you about the process here. Our product fully supports Woo returns. A user can return one or more items, including tickets, using WooCommerce. When they return a ticket it will be get marked as returned in the attendee list, and the customer can even get their money back if you so wish. Would using Woo’s return product workflow work better for you here? If so, I don’t think any customization will be necessary.

    Cheers!

    – Brook

    #1217233
    Bram Huisman
    Participant

    Wait what.. i don’t know anything about this? Can you give me some more information?

    Is Woo return an extension? If so.. which extension are you talking about
    Do you know the customer himself needs to be able to cancel? so not the admin!
    Can you tell me exactly how this works and how this can be achieved.. i’ve searched the documentation over and over.. but could not find it! This thing has a high priority for me.. next week it needs to be live

    Greetz,

    #1217946
    Bram Huisman
    Participant

    Oh and.. if a customer returns a ticket.. does it get deleted so the ticket becomes available again?

    #1218533
    Bram Huisman
    Participant

    Is there nobody who could help me?

    #1220899
    Brook
    Participant

    Howdy Again Bram,

    I am very sorry for the delay. This topic was mismarked on our end as already having a response!

    Is Woo return an extension? If so.. which extension are you talking about
    Do you know the customer himself needs to be able to cancel? so not the admin!

    As an admin you can refund a Woo order by following these steps.

    However, since it sounds like you need the customers themselves to make this request through the website you might be interested in this extension: WooCommece Extension: Returns and Warranty Requests. Put simply, this extension adds a button to the user’s “My Orders” page. The button can be labeled anything you want it to be, such as “Request refund”, “Cancel order”, etc. When someone clicks this button they are given a short form they can fill out, and when they submit the form an email is sent to you with the return request. From there you can approve or disapprove the return. The extension has a lot of other features you probably don’t need if you’re just selling tickets, so you could ignore those.

    Just in case the above is not what you’re looking for, I want to circle back to your original question:

    Everything works.. except one BIG thing.. if a user clicks delete on the front-end the WHOLE ticket gets deleted.. It only needs to delete this specific attendee.. not the whole ticket.

    It sounds like you would be happier with updating the status of the Order, rather than using our delete_ticket() method. You could set the status of the order to refunded using Woo’s API. When the order is refunded the ticket still remains in your list, but it is clearly marked as refunded and the “Check In” button is not available.

    The only difficulty here is that an entire order needs to be refunded. Let’s say one person checks out with two tickets in their cart, then later decides they want to return one of them but keep the other. If you set the order status to refunded, both tickets will become unavailable. I suspect this might be what your developer was referring to when they said “it’s not possible”. Does this situation happen very often, or is it rare enough you could handle this “manually”? If you can not handle this manually, then what your developer has already built is your only good option.

    Does that all make sense? Will that work for you? Please let me know.

    Cheers!

    – Brook

    #1220917
    Bram Huisman
    Participant

    Hi Brook,

    Ghehe it did take a while.. but i am happy you guys responded again. Ehm both options you described don’t fit what i want. Let me tell you how our platform is gonna be:

    It’s a platform for volunteers and when a volunteer is connected to one of our organisations all the workshops will be free of cost (we achieve this with specific roles). All other volunteers need to buy each workshops (all workshops cost 3 euro). For the large amount of all user (around 500 ppl) every workshop will be free. For some not.

    Because it’s gonna be a large platform, we don’t want to do things manually. You probally can imagine that it’s much easier for a “free” user to just cancel their ticket so it becomes available again for others. We don’t need to approve this, because yeah, the ticket was free. We only need the ticket to be pushed back again.. so other people can buyt it.

    For the users who bought a ticket it’s different. We had a long brainstorm over it and this is how we want to achieve it: When a user has bought a ticket, but is not able to come they go to my account –> push the request a refund button –> the ticket needs to be removed from the attendee’s list and after that we send a e-mail to the admin to manually refund the order.. When someone has bought more tickets we can just refund 3 euros (this is possible from within woocommerce).

    Everything from above is already achieved!! The 🙂 tonly thing we can’t achieve is to DELETEhe ticket.. why is this possible on the backend but not on the front-end? The situation now is like this:

    When a user clicks cancel this ticket.. the whole ticket gets removed at this point.. but we only want to remove that specific ticket_id which is attached to that specific user.

    When you check in a customer @ an event you see something like this: ticket with ticket-id 437 has correctly checked in. Do you get what i am trying to explain?

    Pls check out our code we’ve made.. it’s the only thing that doesn’t work http://jsbin.com/mojedejepo/edit?html

    #1222312
    Brook
    Participant

    Howdy again,

    Thank you for clarifying!

    Since you said the ticket was getting deleted, and not the attendee, I wanted to have a second look at your code. The code is not complete, so I can not test it out and there are a few gray areas. However I think I understand why the ticket and not the attendee is getting deleted.

    Inside your delete ticket function you are calling Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance()->delete_ticket(). But instead of passing it the attendee ID in the second argument, you appear to be passing the ticket ID. This method will delete anything you pass to it, so if you send it a Ticket ID and not an attendee it will delete the ticket. Your programmer can view the code that powers it in: /event-tickets-plus/src/Tribe/Commerce/WooCommerce/Main.php and go down to line 973, or simply enough can just change the Ticket ID to the attendee ID. Likely this will fix the bug you’ve encountered.

    Did that help?

    Cheers!

    – Brook

    #1222838
    Bram Huisman
    Participant

    Thx Brooke, the problem is solved and everything works as it should!

    Greetz and many thx!

    #1222935
    Brook
    Participant

    Excellent news! Thanks for getting back.

    – Brook

    #1235461
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Delete ticket on the front-end’ is closed to new replies.