Modern Events Calendar: get info about the available tickets - createIT

Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.


    Modern Events Calendar: get info about the available tickets

    Modern Events Calendar: get info about the available tickets

    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).

    calendar screenshot with days

    Booking system

    We need to follow a few steps to configure a booking system in MEC Pro:

    1. Import Dummy Events
    2. Wp-admin / M.E. Calendar / Settings / Booking – ‘Enable booking module’
    3. Edit a particular event, scroll to the ‘Booking’ MetaBox and define Tickets. Make sure to fill in the ‘Available Ticket’ field.
    4. Go to a single event page, for example: /events/monthly-on-27th/ – the book event form should be visible.
    Event calendar app window with tickets tab opened

    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:

    Table showing ticket availability

    Here is the main file needed for plugin activation:

    // 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' ) ) {
     * Currently plugin version.
     * Start at version 1.0.0 and use SemVer -
     * 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:

    // 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];
                $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:

    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

    FeaturesMEC 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
    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.

    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    How to Get and Use the ChatGPT API
    • Dev Tips and Tricks

    How to Get and Use the ChatGPT API

    April 25, 2024 by createIT
    eCommerce growth – is your business ready?
    • Services
    • Trends

    eCommerce growth – is your business ready?

    April 8, 2024 by createIT
    Digital marketing without third-party cookies – new rules
    • Technology
    • Trends

    Digital marketing without third-party cookies – new rules

    February 21, 2024 by createIT
    eCommerce healthcheck
    • Services
    • Trends

    eCommerce healthcheck

    January 24, 2024 by createIT
    Live Visitor Count in WooCommerce with SSE
    • Dev Tips and Tricks

    Live Visitor Count in WooCommerce with SSE

    December 12, 2023 by createIT
    Calculate shipping costs programmatically in WooCommerce
    • Dev Tips and Tricks

    Calculate shipping costs programmatically in WooCommerce

    December 11, 2023 by createIT
    Designing a cookie consent modal certified by TCF IAB
    • Dev Tips and Tricks

    Designing a cookie consent modal certified by TCF IAB

    December 7, 2023 by createIT

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us