Created
May 25, 2017 17:22
-
-
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.
This file contains 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 | |
/* 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