Skip to content

Instantly share code, notes, and snippets.

@mrwweb
Created September 29, 2023 18:24
Show Gist options
  • Save mrwweb/3aacae7055335dce5f157c086a8d0d2c to your computer and use it in GitHub Desktop.
Save mrwweb/3aacae7055335dce5f157c086a8d0d2c to your computer and use it in GitHub Desktop.
Set Default State/Country in Community Events plugin from The Events Calendar
<?php
/**
* The Community Events plugin offers a "Single Geography" mode but no way
* to specify the default State and Country to use for venues created when
* it's enabled.
*
* Note: Events Calendar PRO allows specifying a default State and Country
* but that shouldn't be required to use Community Events!
*/
namespace SiteName\CommunityEvents;
add_filter( 'tribe_events_community_sanitize_submission', __NAMESPACE__ . '\add_default_state' );
/**
* Set State and Country defaults for all Venues submitted through Community Events front-end form
*/
function add_default_state( $entry ) {
// check if the State has been set by the
if( empty( $entry['Venue']['State'] ) ) {
$entry['Venue']['State'] = [ 'WA' ]; // Use two-letter state abbreviation
$entry['Venue']['Country'] = [ 'United States' ]; // use spelled-out country name
}
return $entry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment