Delete event ticket link in a past event
-
Hi!
Would be possible not displaying the event ticket link if the event has finished?
How can I do it?
Thanks
-
Yes, of course.
You may use for e.g. em_single_event_tickets filter hook. It allows you to control ticket data.
Try ths like this in functions.php:
function custom_em_single_event_tickets( $tickets ) { $post_id = get_the_ID(); if ( $post_id ) { // get event date $end_date = em_get_the_end( $post_id ); // check if event has passed if ( strtotime( $end_date ) < current_time( 'timestamp' ) ) { $tickets = array(); } } return $tickets; } add_filters( 'em_single_event_tickets', 'custom_em_single_event_tickets' );
I’m getting this error:
Call to undefined function add_filters() in…
I display events url in my content-single-event template like this:
<?php if (!function_exists('em_display_event_tickets_url')){ function em_display_event_tickets_url($post_id = 0){ $post_id = (int)(empty($post_id) ? get_the_ID() : $post_id); $tickets_url = get_post_meta($post_id, '_event_tickets_url', true); if ($tickets_url) : ?> <?php if(ICL_LANGUAGE_CODE=='es') { ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLAZA', 'events-maker'); ?></span></a></p> <?php }elseif(ICL_LANGUAGE_CODE=='ca'){ ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLA?A', 'events-maker'); ?></span></a></p> <?php } ?> <?php endif; } } ?> <?php // Display button get ticket em_display_event_tickets_url(); ?>
Am I doing somthing in a bad way?
Thanks so much for the help.
Sorry, it should be add_filter.
But your method would be ok too – just take a look at my code above to see how to check if the event has past.
I’m checking if the event has past with your piece of code, but I think it doesn’t making effect when compare both dates.
I don’t understand what I’m doing wrong.
<?php if (!function_exists('em_display_event_tickets_url')){ function em_display_event_tickets_url($post_id = 0){ // get event date //$post_id = (int)(empty($post_id) ? get_the_ID() : $post_id); $post_id = get_the_ID(); $end_date = em_get_the_end( $post_id ); // get ticket url $tickets_url = get_post_meta($post_id, '_event_tickets_url', true); // check if event has passed if ( strtotime( $end_date ) < current_time( 'timestamp' )) { if(ICL_LANGUAGE_CODE=='es') { ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="#" target="_blank"><span class="text"><?php _e('SOLICITAR MATERIALES', 'events-maker'); ?></span></a></p> <?php }elseif(ICL_LANGUAGE_CODE=='ca'){ ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="#" target="_blank"><span class="text"><?php _e('SOL·LICITAR MATERIALS', 'events-maker'); ?></span></a></p> <?php } }else{ ?> <?php if(ICL_LANGUAGE_CODE=='es') { ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLAZA', 'events-maker'); ?></span></a></p> <?php }elseif(ICL_LANGUAGE_CODE=='ca'){ ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLA?A', 'events-maker'); ?></span></a></p> <?php } ?> <?php } } } ?> <?php // Display button get ticket em_display_event_tickets_url(); ?>
Please check what is the output of those two:
echo strtotime( $end_date );
echo current_time( ‘timestamp’ );strtotime = 1442511610
current_time = no resultI’ve tryied this:
strtotime (“now”) = a number like strtotime($end_date)
But the conditional didn’t work with “now” neither.
It should work – it’s just comparing two numbers.
But isn’t the em_display_event_tickets_url() function out of the condition? It will be always displayed.
I wrote the code in a different way with the function em_display_event_tickets_url() inside de condition, but I haven’t new results :
<?php // get event date $post_id = get_the_ID(); $end_date = em_get_the_end( $post_id ); // check if event has passed if ( strtotime( $end_date ) < strtotime('now') ) { if(ICL_LANGUAGE_CODE=='es') { ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="#" target="_blank"><span class="text"><?php _e('SOLICITAR MATERIALES', 'events-maker'); ?></span></a></p> <?php }elseif(ICL_LANGUAGE_CODE=='ca'){ ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="#" target="_blank"><span class="text"><?php _e('SOL·LICITAR MATERIALS', 'events-maker'); ?></span></a></p> <?php } }else{ if (!function_exists('em_display_event_tickets_url')){ function em_display_event_tickets_url($post_id = 0){ $post_id = (int)(empty($post_id) ? get_the_ID() : $post_id); // get ticket url $tickets_url = get_post_meta($post_id, '_event_tickets_url', true); ?> <?php if(ICL_LANGUAGE_CODE=='es') { ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLAZA', 'events-maker'); ?></span></a></p> <?php }elseif(ICL_LANGUAGE_CODE=='ca'){ ?> <p class="curso_btn"><a class="sf-button standard accent standard ml0" href="<?php echo esc_url($tickets_url); ?>" target="_blank"><span class="text"><?php _e('RESERVAR PLA?A', 'events-maker'); ?></span></a></p> <?php } ?> <?php } } // Display button get ticket em_display_event_tickets_url(); }?>
- The topic ‘Delete event ticket link in a past event’ is closed to new replies.