Support

Home Forums Event Espresso Premium Venue against each date

Venue against each date

Posted: October 3, 2015 at 8:44 am

Viewing 25 reply threads


Zoe E

October 3, 2015 at 8:44 am

Hi all, I have a client that needs a different venue against each date for any given event. I was going to create my own table that would simple contain the ID of the venue and the ID of the datetime (since all dates and venues are pulled from a 3rd party system and automatically inserted I dont need to worry about an interface).

However, they also want the correct venue details to appear in the email – how can I do this? Can I create my own shortcode for the emails?

Cheers 🙂


Seth Shoultes

  • Support Staff

October 5, 2015 at 11:15 am

Are you using EE3 or EE4?


Zoe E

October 5, 2015 at 11:26 am

EE4!


Josh

  • Support Staff

October 6, 2015 at 11:15 am

Hi Zoe,

Yes it’s possible to add your own custom message shortcodes. While we don’t currently have step by step developer documentation that shows how to register new message shortcodes, the Event Espresso 4 ticketing add-on registers its own message shortcodes via the plugin API. I can recommend stepping through the code in the ticketing add-on to learn how to make your own messages shortcodes in a little plugin.


Zoe E

October 14, 2015 at 8:11 am

I dont think we’re using the ticketing plugin for any of our clients (I can’t find it anywhere and its not in my downloads) – is it possible to get a copy of the relevant code?


Josh

  • Support Staff

October 14, 2015 at 2:06 pm

It turns out that Event Espresso 4 core also uses the same API to register new shortcodes. You’ll find examples in EE_Caf_Messages.class.php.


Zoe E

October 15, 2015 at 1:52 am

Thanks Josh, we create our own shortcodes quite often, does any registered shortcode work in the emails?

Thanks!


Josh

  • Support Staff

October 15, 2015 at 11:18 am

Hi Zoe,

Only shortcodes that are specifically registered for messages can be used in messages.


Zoe E

October 16, 2015 at 8:43 am

Hi Josh, I’ll be honest I’m struggling a little here. I already have my shortcode I just can’t figure out how to register it for the messages without editing ee core files.

I’ve found the EE_Register_Shortcode class but don’t know how to hook in to or replicate this outside of the ee core files.

Help!!


Tony

  • Support Staff

October 20, 2015 at 6:21 am

Hi Zoe E,

There’s basically 2 steps to registering a new shortcode with the EE Messages system. Firstly you register the shortcode and where it can be used, here is an example of how you would do that:

function register_new_tony_shortcodes( $shortcodes, EE_Shortcodes $lib ) {

	if ( $lib instanceof EE_Datetime_Shortcodes ) {
		$shortcodes['[TONYS_SHORTCODE]'] = _('This is Tonys Custom Shortcode!');
	}

	return $shortcodes;
}
add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_new_tony_shortcodes', 10, 2 );

That function hooks into the EE Message shortcodes and adds ‘[TONYS_SHORTCODE]’ to the EE_Datetime_Shortcodes.

Then you need to tell EE what to do with the shortcode when it finds it within the message. We do that by adding shortcode a parser. Here is an example of how you add a parser:

function register_new_tony_shortcodes_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
	if ( $lib instanceof EE_Datetime_Shortcodes  && $data instanceof EE_Datetime ) {
		if ( $shortcode == '[TONYS_SHORTCODE]' ) {
			
			return $data->ID();

		}
	}
	return $parsed;
}
add_filter( 'FHEE__EE_Shortcodes__parser_after', 'register_new_tony_shortcodes_parser', 10, 5 );

We are hooking into the shortcodes after EE has done it’s thing and parsing our shortcode.

$parsed is the currently parse content and must be returned (or you’ll have nothing to send)
$shortcode is the current shortcode to be parsed.
$data is the current object passed to the library.

So we check if we are currently within the EE_Datetime_shortcodes library:

if ( $lib instanceof EE_Datetime_Shortcodes )

If so we want to find our specific shortcode:

if ( $shortcode == '[TONYS_SHORTCODE]' )

In this case I’m just returning the ID of the current datetime:

return $data->ID();

But you will be using that to pull venue info from your custom table and returning that information instead.

Here’s a gist containing both those functions as its easier to read:

https://gist.github.com/Pebblo/e87cc8e30c4848dcdfe2

Does that help?

  • This reply was modified 9 years, 1 month ago by Tony. Reason: Fixed code formatting
  • This reply was modified 9 years, 1 month ago by Tony. Reason: updated code


Tony

  • Support Staff

October 21, 2015 at 7:04 am

Also just to clarify for future readers, the EE Messages shortcodes are not standard WordPress shortcodes.

They are specific shortcodes registered within the messages system and can only be parsed within that system, so WordPress shortcodes will not work within the message system and EE Message shortcodes will not work outside of the message system.


Zoee

November 1, 2015 at 3:20 am

Hi all, Thanks for the code above, very very useful. I’ve created my shortcode but am struggling with testing it – I’ve just placed an order but no email confirmation has arrived. Also when I view the receipt on the website (the one thats linked to on the order confirmation screen) I get these errors – are the two things related? Could my shortcode be causing this?

Also is there a way to test the short code without placing a full order. It’d be nice to be able to test it more quickly to iron out any bugs before testing it full in the email.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘register_new_get_custom_venue_dates’ not found or invalid function name in /home/devhrtrainingco/public_html/wp-includes/plugin.php on line 213

Warning: array_key_exists() expects parameter 2 to be array, null given in /home/devhrtrainingco/public_html/wp-content/plugins/event-espresso-core-reg/core/helpers/EEH_Parse_Shortcodes.helper.php on line 236

Thanks!


Tony

  • Support Staff

November 1, 2015 at 6:27 am

Yes it is likely your custom functions causing this.

Also is there a way to test the short code without placing a full order. It’d be nice to be able to test it more quickly to iron out any bugs before testing it full in the email.

Currently the messages are only parsed when sending the message, so the only way to test it is by sending the message.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘register_new_get_custom_venue_dates’ not found or invalid function name in /home/devhrtrainingco/public_html/wp-includes/plugin.php on line 213

Double check the naming of your functions and that they match up with the callback within the filter

Warning: array_key_exists() expects parameter 2 to be array, null given in /home/devhrtrainingco/public_html/wp-content/plugins/event-espresso-core-reg/core/helpers/EEH_Parse_Shortcodes.helper.php on line 236

Double check you are returning the shortcodes array within the functions used to register the shortcode and the parsed content within the parser. EE is expecting an array of shortcodes and is being passed nothing (null)


Zoee

November 3, 2015 at 4:04 am

Hi Tony, thanks for your help on this. I’ve spotted why the first error is occuring but not sure about the second one, the shortcode is being registered exactly as your example above (just with the names changed) so I pressume its coming from this function:

function register_new_get_custom_venue_dates_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
	if ( $lib instanceof EE_Datetime_Shortcodes ) {
		if ( $shortcode == '[get_custom_venue_dates]' ) {

				global $wpdb;

				$thevenues = $wpdb->get_results("SELECT DISTINCT evm.VNU_address, evm.VNU_address2, evm.VNU_city, evm.VNU_zip FROM ".$wpdb->prefix."esp_venue_meta evm 
					INNER JOIN ".$wpdb->prefix."custom_esp_date_venue cdv ON cdv.VNU_ID = evm.VNU_ID 
					WHERE cdv.DTT_ID_ID = '" . $data->ID() . "'");

				$output = "";
				foreach ( $thevenues as $thevenue ) :
					$output = $output.$thevenue->VNU_address."<br />";
					$output = $output.$thevenue->VNU_address2."<br />";
					$output = $output.$thevenue->VNU_city."<br />";
					$output = $output.$thevenue->VNU_zip."<br><br>";
				endforeach;

				return $output;	
		}
	}
return $parsed;
}

but I’m not sure what I need to do to ensure it returns my data as an array?

Thank you 🙂


Tony

  • Support Staff

November 4, 2015 at 5:52 am

To double check if it is that function, comment out the code and just use:

return $data->ID();

Then check that the shortcode parses to the ID of the datetime.

Can you post up both functions please, however I would recommend using something like http://pastebin.com/ and a Gist as the forum alters the formatting slightly.

The code this is failing is when EE tries to pull in all of the shortcodes for a message type and check if the shortcode exists, so I think its where you are registering your shortcode, rather than when you are trying to parse it.


Zoee

November 5, 2015 at 9:43 am

Thanks Tony, I’ll give that a go now.

Here are both my functions 🙂 http://pastebin.com/x2pfeJS7


Zoee

November 5, 2015 at 10:01 am

Interesting – I just reinserted my shortcode in to the receipt email and I got this message:

An error has occurred:

The following shortcodes were found in the “Main Content” field that ARE not valid: [get_custom_venue_dates]


Tony

  • Support Staff

November 5, 2015 at 1:30 pm

That’s because your using a shortcode you have registered within EE_Datetime_Shortcodes within the main content, EE_Datetime_SHortcodes are not valid within the main content section.

You need to use that shortcode within the Datetime_list section – http://take.ms/QOJHm

I’ve just pasted both your functions into my functions.php file, swapped out the return for just a string – http://take.ms/K5nzX.

Then tested that within the messages and it worked fine.

Obviosuly I can’t set your other code as the query won’t work but was your eventually just returning a string it should work.

Have you tried returning a var_dump() of $thevenues?

You can do that using output buffering or even using var_export, have a read here:

http://stackoverflow.com/questions/139474/how-can-i-capture-the-result-of-var-dump-to-a-string

Then see if $thevenues actually has values.


Zoee

November 5, 2015 at 3:49 pm

Awesome, I have it working now 🙂 One last sort of related q – my mini basket buttons link to my live site (I moved my site to a dev URL) – where are these set? I’ve replaced all the URLs in my database.

Cheers 😀


Tony

  • Support Staff

November 6, 2015 at 3:39 am

Can I ask what the problem was?

Which links are these? Can you link me to the page?

Did you replace the URLs manually? I remember from your other thread you mentioned replacing the URLs though phpMyAdmin.


Zoee

November 6, 2015 at 4:36 am

I exported the database and did a find and replace in a text editor so I know theres none left in there 🙂


Tony

  • Support Staff

November 9, 2015 at 3:45 am

Can you link me to the page so I can view this please?


Zoee

November 9, 2015 at 3:52 am

Sure, its http://dev.hr-training.co.uk/courses/test-course/


Tony

  • Support Staff

November 9, 2015 at 4:54 am

Have you flushed your Permalinks?

Go to Dashboard -> Settings -> Parmalinks

Make no changes and save the settings.

If that doesn’t work go to Event Espresso -> General Settings -> Critical pages.

Then save the settings there and retest.


Zoee

November 9, 2015 at 6:47 am

Hi Tony, have just done both of those and those URLs are still wrong. I dont understadn where they are coming from as a find in our theme/mu-plugins returns nothing as does a find on the entire database.


Tony

  • Support Staff

November 9, 2015 at 7:05 am

It uses the WP core function get_permalink() to build those links. The view cart link is built using the reg_page_url() function within EE core, which is just:

public function reg_page_url() {
	if ( ! $this->reg_page_url ) {
		$this->reg_page_url = get_permalink( $this->reg_page_id ) . '#checkout';
	}
	return $this->reg_page_url;
}

So it seems get_permalink() is returning your old URL, so WordPress (not EE) still thinks its on the old url.

If you look within Dashboard -> Settings -> General.

Are your WordPress URL and Site URL values setup using the dev domain?

It could also be a plugin/the theme filtering get_permalink to use your old URL.

Viewing 25 reply threads

The support post ‘Venue against each date’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso