Last active
March 7, 2018 08:15
-
-
Save gordielachance/6a91077796d5d17c75c635f20dbec86e to your computer and use it in GitHub Desktop.
The Events Calendar - Open Price module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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