The Modern Events Calendar (MEC) features a free version (called Lite). It’s an event management plugin for WordPress which makes selling tickets easy.
Are you in need of custom integration with a MEC plugin? Or do you need to fetch custom details about events or tickets, but the default shortcodes are not providing it out of the box? After analyzing how the plugin works, we display info about tickets as custom shortcode.
In this tutorial, we’re focusing on MEC Pro. It’s a premium version that includes a booking system and an option to generate tickets. The premium version is available for $75 with Lifetime Auto Updates for 1 site. This means it’s a one-time payment (no need to extend a subscription every year).
Booking system
We need to follow a few steps to configure a booking system in MEC Pro:
- Import Dummy Events
- Wp-admin / M.E. Calendar / Settings / Booking – ‘Enable booking module’
- Edit a particular event, scroll to the ‘Booking’ MetaBox and define Tickets. Make sure to fill in the ‘Available Ticket’ field.
- Go to a single event page, for example: /events/monthly-on-27th/ – the book event form should be visible.
Custom WP plugin
For presentation purposes, we’re going to create a custom WordPress plugin that will register shortcode. We will create a listing with all events and calculate how many tickets are still available, as well as the number of tickets already sold. The plugin includes shortcode [ct_query_mec] that will render the results.
The most important method is get_tickets_availability(). Instead of writing it from scratch, we are reusing the original plugin method from the MEC_book class (file location: wp-content/plugins/modern-events-calendar/app/libraries/book.php ).
$book_class = new MEC_book();
$book = $book_class->getBook();
The MEC_book PHP class is available globally to use, so we can init it in our shortcode. Occurence_time, which is the second parameter for the get_tickets_availability() function is somewhat mysterious. Firstly, it’s difficult to say what proper value we should provide. It turns out it’s the timestamp of the event’s starting moment. This value is fetched using the get_post_meta WP method.
$start_date = get_post_meta($event->ID, 'mec_start_date', true);
$start_time = get_post_meta($event->ID, 'mec_start_day_seconds', true);
// $occurrence_time = 1645948800;
$occurrence_time = strtotime($start_date) + $start_time;
To better understand how timestamp is calculated, let’s inspect the wp_postmeta table. mec_start_date and mec_start_day_seconds are the values we’re using:
meta_id | post_id | meta_key | meta_value |
55 | 6 | mec_start_date | 2022-02-28 |
56 | 6 | mec_start_time_hour | 8 |
57 | 6 | mec_start_time_minutes | 0 |
58 | 6 | mec_start_time_ampm | AM |
59 | 6 | mec_start_day_seconds | 28800 |
60 | 6 | mec_end_date | 2022-02-28 |
61 | 6 | mec_end_time_hour | 6 |
62 | 6 | mec_end_time_minutes | 0 |
Here is the main file needed for plugin activation:
<?php
// wp-content/plugins/ct-query-mec/ct-query-mec.php
/**
* Plugin Name: CT Query MEC
* Description: Fetch custom details from MEC database structure
* Version: 1.0.0
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'YOUR_PLUGIN_SLUG_VERSION', '1.0.0' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/shortcodes.php';
And a shortcode function for displaying MEC Ticket info:
<?php
// wp-content/plugins/ct-query-mec/includes/shortcodes.php
function ct_get_available_tickets_func() {
if(! class_exists('MEC_book')){
include( WP_PLUGIN_DIR . '/modern-events-calendar/app/libraries/book.php');
}
$output = '';
$book_class = new MEC_book();
$book = $book_class->getBook();
$args = array(
'post_type' => 'mec-events',
'posts_per_page' => -1,
'post_status' => array('publish'),
);
$events = get_posts($args);
$listing = '<h1>Ticket availability</h1>';
foreacH($events as $event){
$start_date = get_post_meta($event->ID, 'mec_start_date', true);
$start_time = get_post_meta($event->ID, 'mec_start_day_seconds', true);
// $occurrence_time = 1645948800;
$occurrence_time = strtotime($start_date) + $start_time;
$availability = $book->get_tickets_availability($event->ID, $occurrence_time);
$availability_text = '';
if(isset($availability[1])) {
$availability_text = $availability[1];
}
if($availability_text){
$listing .= '<div class="events-listing">';
$listing .= '<h2><a href="'. get_permalink($event->ID) .'">'. $event->post_title .'</a></h2>';
$listing .= '<p>Tickets available: ' . $availability_text . '</p>';
$listing .= '<p>Tickets sold: ' . $book->get_all_sold_tickets($event->ID) . '</p>';
$listing .= '</div>';
$listing .= '<br><br><br>';
}
}
$output .= $listing;
$output .= '[MEC id="19"]';
// $event_id = 7;
// $output .= '[mec-booking event-id="' . $event_id .'"]';
return do_shortcode($output);
}
// register shortcode
add_shortcode('ct_query_mec', 'ct_get_available_tickets_func');
That’s it. The last step will be to activate the plugin and add [ct_query_mec] to page content. The listing will be rendered.
MEC Free vs Pro
Modern Events Calendar Pro includes many interesting features, such as a booking system (ticket generation), QR codes, reminder notifications and additional shortcodes. The plugin offers good price-quality ratio. In comparison to its competition, it is more feature-rich and has a better pricing point.
The MEC plugin also offers a rich list of paid add-ons. The add-ons integrate with existing WordPress plugins, like WooCommerce or Elementor. They may also add extra functionality to Events. It’s worth to mention that add-ons often don’t need the Pro version, and can work with the free one. More info: https://webnus.net/mec-purchase/
The basic functionality is often enough to start your Event listing and gather event submissions from the plugin form. Let’s inspect the features table to have a better overview of the features of the free/Lite version vs. Premium. You can check it out and see if paying extra is worth it.
Modern Evens Calendar – features table comparison
Features | MEC Lite (Free) | MEC (Pro) |
Single day events | ✔ | ✔ |
Multiple day events | ✔ | ✔ |
All day events | ✔ | ✔ |
Full Calendar view | ✔ | ✔ |
Monthly calendar view | ✔ | ✔ |
Daily view | ✔ | ✔ |
Weekly view | ✔ | ✔ |
Countdown view | ✔ | ✔ |
Grid & cover view | ✔ | ✔ |
Slider & carousel view | ✔ | ✔ |
List View | ✔ | ✔ |
Event locations system | ✔ | ✔ |
Event venue & organizer system | ✔ | ✔ |
Multiple organizers | ✔ | ✔ |
Front-end Event Submission | ✔ | ✔ |
Never end events | ✔ | ✔ |
Event widgets & sidebar | ✔ | ✔ |
Custom sidebar | ✔ | ✔ |
Recurring/Repeating events | ✔ | ✔ |
Shortcodes generator | ✔ | ✔ |
Direct/Modal link for single event | ✔ | ✔ |
Show/Hide option for search bar | ✔ | ✔ |
Filtering options | ✔ | ✔ |
Google calendar integration | ✔ | ✔ |
Reporting dashboard | ✔ | ✔ |
Local time | ✔ | ✔ |
Manage Notifictions | ✔ | ✔ |
RSS feed | ✔ | ✔ |
Schedule for single event | ✔ | ✔ |
Download .ics file | ✔ | ✔ |
Social share icons | ✔ | ✔ |
Custom Color | ✔ | ✔ |
Search Bar Shortcode | ✔ | ✔ |
Breadcrumb | ✔ | ✔ |
Schema Ready | ✔ | ✔ |
QRcode module | ❌ | ✔ |
Reminders notification | ❌ | ✔ |
Organizer Payment | ❌ | ✔ |
Customizable Notifications Emails | ❌ | ✔ |
Complete Repeating | ❌ | ✔ |
Ticket price per date | ❌ | ✔ |
Customizable Timetable | ❌ | ✔ |
Import .ics file | ❌ | ✔ |
Auto Update | ❌ | ✔ |
Map view + Directions | ❌ | ✔ |
Agenda view | ❌ | ✔ |
Masonry view | ❌ | ✔ |
Timetable view | ❌ | ✔ |
Available spot | ❌ | ✔ |
Ticketing system | ❌ | ✔ |
Booking system | ❌ | ✔ |
Booking form builder | ❌ | ✔ |
Booking Calendar | ❌ | ✔ |
Weather module | ❌ | ✔ |
Premium Support | ❌ | ✔ |
Total Price | $0.00 | $75 |
That’s it for today’s suggestions. Make sure to follow us for other useful tips and guidelines, and don’t forget to subscribe to our newsletter.
Comments
0 response