Skip to content

Instantly share code, notes, and snippets.

@gordielachance
Last active March 7, 2018 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordielachance/6a91077796d5d17c75c635f20dbec86e to your computer and use it in GitHub Desktop.
Save gordielachance/6a91077796d5d17c75c635f20dbec86e to your computer and use it in GitHub Desktop.
The Events Calendar - Open Price module
<?php
//Add this in your functions.php file
add_action( 'tribe_events_cost_table', 'event_backend_open_price', 9 );
add_action( 'tribe_events_event_save', 'event_save_open_price', 10, 3 );
add_filter( 'tribe_get_cost','event_get_open_price',10,3);
function event_backend_open_price($event_id){
$isOpenPrice = ($event_id) ? get_post_meta( $event_id, '_EventOpenPrice', true ) : false;
?>
<tr>
<td><?php esc_html_e( 'Open Price:', 'labokube' ); ?></td>
<td>
<input
tabindex="<?php tribe_events_tab_index(); ?>"
type="checkbox"
id="openPriceCheckbox"
name="EventOpenPrice"
value="1"
<?php checked( $isOpenPrice ); ?>
/>
</td>
</tr>
<tr>
<td></td>
<td>
<small><?php echo esc_html__( 'Use the price field above as a suggested price.', 'labokube' ); ?></small>
</td>
</tr>
<?php
}
function event_save_open_price($event_id, $data, $event){
$isOpenPrice = isset($_POST['EventOpenPrice']);
if ($isOpenPrice){
update_post_meta($event_id,'_EventOpenPrice',true);
}else{
delete_post_meta($event_id,'_EventOpenPrice');
}
}
function event_get_open_price($cost, $event_id, $with_currency_symbol){
$isOpenPrice = get_post_meta( $event_id, '_EventOpenPrice', true );
if ($isOpenPrice){
if ( $cost == esc_html__( 'Free', 'the-events-calendar' ) ) $cost = null; //free
if ($cost){
$suggested_txt = sprintf( '<small>' . __("suggested: %s","labokube") . '</small>',$cost );
$cost = sprintf(__("Open Price - %s","labokube"),$suggested_txt);
}else{
$cost = __("Open Price","labokube");
}
}
return $cost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment