Skip to content

Instantly share code, notes, and snippets.

@vicskf
Created May 25, 2017 17:22
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 vicskf/f4dc5cf320106ce0b59a3a5f7f547f3f to your computer and use it in GitHub Desktop.
Save vicskf/f4dc5cf320106ce0b59a3a5f7f547f3f to your computer and use it in GitHub Desktop.
TEC > Community Events > Custom require Event Cost allowing 0 (zero) as value for free events.
<?php
/* Custom Event Cost validation */
function tribe_custom_event_cost_validation ( $valid, $submission, $class ) {
/* Prevents submit and adds error message if cost is empty and different than '0' */
if ( empty( $submission['EventCost'] ) && $submission['EventCost'] != '0' ) {
$valid = false;
$message = __( '%s is required', 'tribe-events-community' );
$message = sprintf( $message, 'Event Cost');
$class->add_message( $message, 'error' );
}
return $valid;
}
function my_community_add_required_to_fields( $fields ) {
if ( ! is_array( $fields ) ) {
return $fields;
}
$fields[] = 'EventCost';
return $fields;
}
function my_community_custom_required_field() {
add_filter( 'tribe_events_community_required_fields', 'my_community_add_required_to_fields', 10, 1 );
}
add_action( 'tribe_ce_before_event_submission_page_template', 'my_community_custom_required_field', 10, 1 );
add_filter('tribe_community_events_validate_submission', 'tribe_custom_event_cost_validation', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment