Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('em_event_output_placeholder','my_cancel_button',100,3);
- function my_cancel_button( $replace, $EM_Event, $result ){
- global $wpdb;
- if ( $result == '#_EVENTCANCELBUTTON' ){
- $replace = "";
- if ( is_user_logged_in() ){
- if( !isset($user_bookings) || !is_array($user_bookings) ){
- $sql = $wpdb->prepare('SELECT *, booking_status FROM '.EM_BOOKINGS_TABLE.' WHERE person_id=%d AND event_id=%d', array(get_current_user_id(), $EM_Event->event_id));
- if ( $EM_Event->timeslot_id ) {
- $sql .= ' AND timeslot_id=' . absint( $this->timeslot_id );
- }
- $user_bookings = $wpdb->get_results($sql);
- }
- if( !empty($user_bookings) ){
- foreach ( $user_bookings as $EM_Booking ) {
- $nonce = wp_create_nonce('booking_cancel');
- if( in_array( $EM_Booking->booking_status, array(1)) ){
- $cancel_url = em_add_get_params($_SERVER['REQUEST_URI'], array('action'=>'booking_cancel', 'booking_id'=>$EM_Booking->booking_id, '_wpnonce'=>$nonce));
- $replace = '<a class="em-bookings-cancel em-booking-submit button-secondary" href="'. esc_url($cancel_url) .'" onclick="if( !confirm(EM.booking_warning_cancel) ){ return false; }">'.__('Cancel Booking','events-manager').'</a>';
- }
- }
- }
- }
- }
- return $replace;
- }
Advertisement