{"id":1216477,"date":"2017-01-11T06:42:03","date_gmt":"2017-01-11T14:42:03","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/"},"modified":"2017-01-11T06:42:03","modified_gmt":"2017-01-11T14:42:03","slug":"delete-ticket-on-the-front-end","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/","title":{"rendered":"Delete ticket on the front-end"},"content":{"rendered":"<p>Hi there,<\/p>\n<p>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<\/p>\n<p>This function works on the back-end &#8211;&gt; if you choose delete the attendee selected will be deleted. I build a function on my own to enable it on the front end: <\/p>\n<p><code>&lt;div class=\"um-field\"&gt;<br \/>\n            &lt;?php<br \/>\n            $user_id = get_current_user_id();<br \/>\n            $current_user = wp_get_current_user();<br \/>\n            $customer_email = $current_user-&gt;user_email;<\/p>\n<p>            $event_ids = $this-&gt;get_all_attendances($user_id, 0, strtotime('last year'));<br \/>\n            $future_events = [];<br \/>\n            $past_events = [];<\/p>\n<p>            ?&gt;<br \/>\n            &lt;div class=\"um-account-heading uimob340-hide uimob500-hide\"&gt;&lt;i class=\"um-icon-ios-list\"&gt;&lt;\/i&gt;&lt;?php _e('Mijn workshops', 'sage'); ?&gt;&lt;\/div&gt;<\/p>\n<h2>&lt;?php _e('Upcoming events', 'va073'); ?&gt;<\/h2>\n<p>            &lt;ul class=\"tribe-tickets attendance-list-old\"&gt;<br \/>\n                &lt;?php foreach ($event_ids as $id): ?&gt;<br \/>\n                    &lt;?php $start_date = tribe_get_start_date($id, true, 'd F Y') . ' ' . __('om', 'va073') . ' ' . tribe_get_start_date($id, true, 'G:i') . ' ' . __('hour', 'va073');<\/p>\n<p>                    $current_time = current_time('timestamp');<br \/>\n                    $event_date = strtotime(tribe_get_start_date($id, true, 'd-m-Y'));<\/p>\n<p>                    $tickets_provider = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();<br \/>\n                    $tickets_ids = $tickets_provider-&gt;get_tickets($id);<\/p>\n<p>                    $bought_ticket = false;<br \/>\n                    $refund = false;<\/p>\n<p>                    if (!$tickets_ids) continue;<\/p>\n<p>                    foreach ($tickets_ids as $ticket) {<br \/>\n                        if (wc_customer_bought_product($customer_email, $user_id, $ticket-&gt;ID)): $bought_ticket = $ticket-&gt;ID; endif;<br \/>\n                        if (!$bought_ticket): continue 2; endif;<br \/>\n                    }<\/p>\n<p>                    $ticket = $tickets_provider-&gt;get_ticket($id, $bought_ticket);<br \/>\n                    if($ticket-&gt;price != 0 &amp;&amp; $ticket-&gt;regular_price != 0):<br \/>\n                        $refund = true;<br \/>\n                    endif;<\/p>\n<p>                    $attendees_provider = Tribe__Tickets__Tickets::get_event_attendees($id);<br \/>\n                    $attendee_id = 0;<\/p>\n<p>                    foreach ($attendees_provider as $attendee) {<br \/>\n                        if ($attendee['user_id'] == $user_id &amp;&amp; !$attendee['order_warning']):<br \/>\n                            $attendee_id = $attendee['attendee_id'];<br \/>\n                        endif;<br \/>\n                    }<\/p>\n<p>                    if ($event_date &gt; $current_time): array_push($future_events, $id);<br \/>\n                        ?&gt;<br \/>\n                        &lt;li class=\"event-&lt;?php echo esc_attr($id) ?&gt;\"&gt;<\/p>\n<p>                            &lt;span&gt;&lt;?php echo get_the_title($id); ?&gt;&lt;\/span&gt;<br \/>\n                            &lt;span&gt;-&lt;\/span&gt;<br \/>\n                            &lt;?php if ($start_date): ?&gt;<br \/>\n                                &lt;span class=\"datetime\"&gt;&lt;?php echo $start_date; ?&gt;&lt;\/span&gt;<br \/>\n                            &lt;?php endif; ?&gt;<br \/>\n                            &lt;\/br&gt;<br \/>\n                            &lt;?php if(!$refund): ?&gt;<br \/>\n                                <a href=\"#\">\"<br \/>\n                               data-event=\"&lt;?php echo $id; ?&gt;\" data-attendee=\"&lt;?php echo $attendee_id; ?&gt;\" data-user=\"&lt;?php echo $user_id; ?&gt;\"&gt;Uitschrijven<\/a><br \/>\n                            &lt;?php else: ?&gt;<br \/>\n                                <a href=\"#\">\"<br \/>\n                                                 data-event=\"&lt;?php echo $id; ?&gt;\" data-attendee=\"&lt;?php echo $attendee_id; ?&gt;\"&gt;Terugbetaling aanvragen<\/a><br \/>\n                            &lt;?php endif; ?&gt;<br \/>\n                            <a href=\"#\">\"<br \/>\n                               data-event=\"&lt;?php echo $id; ?&gt;\" data-user=\"&lt;?php echo $user_id ?&gt;\"&gt;Download ticket<\/a>\n                        <\/li>\n<p>                    &lt;?php endif;<\/p>\n<p>                endforeach; ?&gt;<\/p>\n<p>                &lt;?php if (empty($future_events)): ?&gt;<\/p>\n<p>                    &lt;li class=\"event-none\"&gt;<br \/>\n                        &lt;?php esc_html_e('U heeft zichzelf niet aangemeld voor een van onze workshops', 'sage'); ?&gt;\n                    <\/li>\n<p>                &lt;?php endif; ?&gt;\n            <\/ul>\n<p><\/code><\/p>\n<p><code>    function delete_ticket()<br \/>\n    {<br \/>\n        check_ajax_referer('va073', 'security');<\/p>\n<p>        $ticket = sanitize_text_field($_POST['ticket']);<br \/>\n        $event = sanitize_text_field($_POST['event']);<\/p>\n<p>        $tickets_provider = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();<br \/>\n        $tickets_provider-&gt;delete_ticket($event, $ticket);<\/p>\n<p>        echo $event;<br \/>\n        exit();<br \/>\n    }<\/code><\/p>\n<p>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.<\/p>\n<p>I know you guys don&#8217;t provide support on customisation.. but my developer which made this code says that it&#8217;s not possible. I find this strange because at the back-end it works? <\/p>\n<p>Can you guys plsssssss help me!<\/p>\n","protected":false},"template":"","class_list":["post-1216477","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Delete ticket on the front-end -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete ticket on the front-end -\" \/>\n<meta property=\"og:description\" content=\"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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/\",\"name\":\"Delete ticket on the front-end -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-01-11T14:42:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Ticket Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Event Tickets Plus\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/event-tickets-plus\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Delete ticket on the front-end\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Delete ticket on the front-end -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/","og_locale":"en_US","og_type":"article","og_title":"Delete ticket on the front-end -","og_description":"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 [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/","name":"Delete ticket on the front-end -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-01-11T14:42:03+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/delete-ticket-on-the-front-end\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Ticket Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/"},{"@type":"ListItem","position":4,"name":"Event Tickets Plus","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/event-tickets\/event-tickets-plus\/"},{"@type":"ListItem","position":5,"name":"Delete ticket on the front-end"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1216477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1216477\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1216477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}