Support

Home Forums Event Espresso Premium EE3:Action/Hook for after a payment confirmation and sucessful reg?

EE3:Action/Hook for after a payment confirmation and sucessful reg?

Posted: May 29, 2014 at 10:10 am

Viewing 12 reply threads


Andrew Dunn

May 29, 2014 at 10:10 am

Hey,

I’m looking to add the registrants email address with CampaignMonitor. Is there a hook or function that I can do this with? So when a sucessful registration has been made, I can execute some code.

<code>function myFunctionAfterRegistration(){
// CampaignMonitor stuff
}
add_action( &#039;myFunctionAfterRegistration&#039;, &#039;ee3_sucessful_registration&#039; );</code>

Any help appreciated 🙂

Thanks!


Josh

  • Support Staff

May 29, 2014 at 9:25 pm

Hi Andrew,

Either action_hook_espresso_track_successful_sale or action_hook_espresso_email_after_payment will work for this job.

https://eventespresso.com/wiki/event-espresso-3-1-action-hooks/#action_hook_espresso_track_successful_sale


Andrew Dunn

June 6, 2014 at 5:32 am

Hello,

I can’t seem to get this hook working – any ideas?

function CM_delegate_import($payment_data) {

require_once(dirname(__FILE__) .’/csrest_subscribers.php’);

$wrap = new CS_REST_Subscribers(‘d4839efe4cece14010247e961fdae905’, ‘a62f907439fb09b96710796738ef3a7a0a5cd2c5b371efa3’);
foreach($payment_data as $data) {
$subscriber = $wrap->add(array(
‘EmailAddress’ => $data[‘contact’],
‘Name’ => $data[‘fname’] . $data[‘lname’],
‘CustomFields’ => array(),
‘Resubscribe’ => true
));
}
}
add_action(‘CM_registration_import’, ‘action_hook_espresso_track_successful_sale’);


Tony

  • Support Staff

June 6, 2014 at 6:15 am

Hi Andrew,

It looks like the add_action call has the functions in the incorrect order.

You want to add your ‘CM_delegate_import’ function to the ‘action_hook_espresso_track_successful_sale’ hook, yet the call is trying to add ‘action_hook_espresso_track_successful_sale’ to your ‘CM_delegate_import’ function.

add_action('CM_registration_import', 'action_hook_espresso_track_successful_sale');

Should be

add_action('action_hook_espresso_track_successful_sale', 'CM_registration_import');

See here for reference:

http://codex.wordpress.org/Function_Reference/add_action


Andrew Dunn

June 6, 2014 at 6:18 am

Hey there,

Thank you for your email – a silly error indeed. Am I accessing the data objects within $payment_data correctly?


Andrew Dunn

June 6, 2014 at 7:09 am

The issue does appear to be accessing the email address, first name & last name within $payment_data. I manually set my CM $data[‘xx’]; and it imported into CM fine.

Can you advise if I am passing $payment_data across OK, and how I can acess the above info easily?

Thanks in advance!


Andrew Dunn

June 6, 2014 at 7:12 am

Here’s the code that I have:

<code>
function CM_delegate_import($payment_data) {

	include_once(DIRNAME(__FILE__).&#039;/csrest_subscribers.php&#039;)

	$wrap = new CS_REST_Subscribers(&#039;key1&#039;, &#039;key2&#039;);
	if(is_array($payment_data)) {
		foreach($payment_data as $data) {
			$subscriber = $wrap-&gt;add(array(
			    &#039;EmailAddress&#039; =&gt; $data[&#039;contact&#039;],
			    &#039;Name&#039; =&gt; $data[&#039;fname&#039;] . $data[&#039;lname&#039;],
			    &#039;CustomFields&#039; =&gt; array(),
			    &#039;Resubscribe&#039; =&gt; true
			));
		}		
	}
}
add_action(&#039;action_hook_espresso_track_successful_sale&#039;, &#039;CM_delegate_import&#039;);</code>


Andrew Dunn

June 6, 2014 at 7:13 am

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”>function CM_delegate_import($payment_data) {

include_once(DIRNAME(__FILE__).'/csrest_subscribers.php')

$wrap = new CS_REST_Subscribers('key1', 'key2');
if(is_array($payment_data)) {
foreach($payment_data as $data) {
$subscriber = $wrap->add(array(
'EmailAddress' => $data['contact'],
'Name' => $data['fname'] . $data['lname'],
'CustomFields' => array(),
'Resubscribe' => true
));
}
}
}
add_action('action_hook_espresso_track_successful_sale', 'CM_delegate_import');


Tony

  • Support Staff

June 6, 2014 at 8:53 am

Are you only wanting to add an attendee to Campaign Monitor if the attendee has successfully paid for a registration or would you like that info as soon as it is available?


Andrew Dunn

June 6, 2014 at 8:55 am

Hello,

For when they have succesfully paid. I’m close, just need a nudge on why I can’t get the data. I have multiple registrants per registration hence the foreach

Thank you in advance.


Tony

  • Support Staff

June 6, 2014 at 10:06 am

Have you tried outputting $payment_data?

Add

var_dump($payment_data);

To the top of your function. Depending on the registration you find different results.


Andrew Dunn

June 9, 2014 at 2:37 am

Hello!

I’ve added var_dump but sadly my code isn’t working. What would be the best way to output or collect the var_dumo / array info in $payment_data?

I suspect my code isn’t working as $payment_data is not an array, or is empty?


Josh

  • Support Staff

June 9, 2014 at 3:03 pm

Hi Andrew,

It turns out $payment_data is an array. You can use print_r to print the values of $payment_data onto the Payment overview page like this:

add_action('action_hook_espresso_track_successful_sale', 'CM_delegate_import', 10);

function CM_delegate_import($payment_data) {
	print_r($payment_data); 
}
Viewing 12 reply threads

The support post ‘EE3:Action/Hook for after a payment confirmation and sucessful reg?’ 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