Skip to content

Instantly share code, notes, and snippets.

@vicskf
Last active April 17, 2018 12:04
Show Gist options
  • Save vicskf/e9f4763809d825a2b768fe83a945c2fd to your computer and use it in GitHub Desktop.
Save vicskf/e9f4763809d825a2b768fe83a945c2fd to your computer and use it in GitHub Desktop.
Event Tickets > For ticketed events, it filter the event cost to only consider ticket price if on sale.
<?php
/**
* For ticketed events, it filter the event cost to only consider ticket price if on sale.
*
* From: https://gist.github.com/vicskf/e9f4763809d825a2b768fe83a945c2fd
*/
add_filter( 'tribe_get_cost', 'custom_tribe_get_cost', 10, 3 );
function custom_tribe_get_cost ( $cost, $post_id, $with_currency_symbol ) {
if ( ! tribe_events_has_tickets( $post_id ) ) {
return $cost;
}
$currency_symbol = '';
if ( $with_currency_symbol ){
$currency_symbol = get_post_meta( $post_id, '_EventCurrencySymbol', true );
}
$prices = array();
foreach ( Tribe__Tickets__Tickets::get_all_event_tickets( $post_id ) as $ticket ) {
if ( tribe_events_ticket_is_on_sale( $ticket ) ) {
if ( !empty( $ticket->price ) ) {
$prices[] = $currency_symbol . $ticket->price;
}
}
}
$cost = implode( ", ", $prices );
return $cost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment