Events Espresso – has_purchased shortcode

July 21, 2015 | Events, PHP, Plugins, Time Savers, Tutorials, Wordpress | 0 comments

I have been working with Events Espresso for a little while now. It’s a comprehensive plugin but it lacks one handy little feature.. we needed the ability to show content based on the attending status of the currently logged in user. So if the logged in user ‘has purchased’ attendance to a specific event (or events list). Adding the following code to your theme functions.php file or a new plugin will give you access to a new shortcode.

The shortcode accepts ‘id’ and ‘noaccess’ arguments. The id accepts a single number for an event or a list of event ids separated by a | character. ‘noaccess’ is optional but when used it will show the provided message when a user has NOT purchased attendance to the event(s) specified.

The code

add_shortcode('ee_has_purchased', 'sb_ee_has_purchased');

function sb_ee_has_purchased($atts, $content) {
	global $wpdb, $current_user;
	$no_access = (isset($atts['noaccess']) ? wpautop($atts['noaccess']):'');
	if ($current_user->ID) {
		if (isset($atts['id'])) {
			if ($ids = explode('|', $atts['id'])) {
				$sql = 'SELECT COUNT(reg.REG_ID) AS attending
						`' . $wpdb->prefix . 'esp_registration` reg
						JOIN `' . $wpdb->prefix . 'esp_attendee_meta` atm ON (reg.ATT_ID = atm.ATT_ID)
						reg.STS_ID IN ("RAP","TCM","ACT")
						AND reg.EVT_ID IN (' . implode(',', $ids) . ')
						AND atm.ATT_email = "' . $current_user->user_email . '"';
				if (!$wpdb->get_var($sql)) { //if not purchased then clear the content
					$content = $no_access;
	} else {
		$content = $no_access;
	return do_shortcode($content);


[ee_has_purchased id="123|345" noaccess="you do not have access to this content"]

A Donate Button!


Submit a Comment

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

CommentLuv badge

Stay in touch!

Page Builder Cloud

Page Builder Cloud

A truly universal template library for WordPress Page Builders.

Page Builder Recommendation

Elementor Banner

We are BIG fans of the Elementor page builder. Give it a look!

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist and Co-Founder of Page Builder Cloud.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!