Support

Home Forums Event Espresso Premium EE4 and WP Affiliate

EE4 and WP Affiliate

Posted: March 19, 2015 at 6:37 am

Viewing 3 reply threads


ds

March 19, 2015 at 6:37 am

Hello,

We have one of the users git hub page about an integration with WP Affiliate. The code us didn’t work so we spent some time going through to see how to get it to work. The action in the original code by the user (see below) didn’t actually work. AHEE__EE_Transaction__finalize__all_transaction it was found in the deprecated file.


function espresso_track_successful_sale( $Transaction, $reg_msg, $from_admin ){
    
	if ($Transaction instanceof EE_Transaction) {
		$sale_amt = $Transaction->paid();
		$unique_transaction_id = $Transaction->ID();
		$Primary_Registration = $Transaction->primary_registration();
		if ($Primary_Registration instanceof EE_Registration) {
			$Attendee = $Primary_Registration->attendee();
			if ($Attendee instanceof EE_Attendee) {
				$email = $Attendee->email();
				$referrer = $_COOKIE['ap_id'];
				do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" =>$sale_amt, "txn_id"=>$unique_transaction_id, "buyer_email"=>$email));
			}
		}
	}
}
add_action('AHEE__EE_Transaction__finalize__all_transaction','espresso_track_successful_sale', 20, 3); 

So this is our rewrite using the AHEE__EE_Transaction_Processor__manually_update_registration_statuses for the applying payment manually, i.e. applying payment on an invoice from the backend.

unfortunately the next function throws an error as the first function does not work with payment gateways such as stripe and paypal as i’m guessing there is an action which sets the registration to paid.

We thought it would be this: AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment

however it throws an error once you click on the finalize payment options button (after you have successful gone through either gateway).

function espresso_track_successful_sale_manual( $Transaction, $status_updates ){
    

	if ($Transaction instanceof EE_Transaction) {
		$sale_amt = $Transaction->paid();
		$unique_transaction_id = $Transaction->ID();
		$Primary_Registration = $Transaction->primary_registration();
		if ($Primary_Registration instanceof EE_Registration) {
			$Attendee = $Primary_Registration->attendee();
			if ($Attendee instanceof EE_Attendee) {

				

				$email = $Attendee->email();
				$referrer = $_COOKIE['ap_id'];

				//throw new Exception("Sale amount: ".$sale_amt.", " .
				//	"unique_transaction_id: ".$unique_transaction_id.", " .
				//	"email: ".$email.", " .
				//	"referrer: ".$referrer.", "
				//	, 1);

				do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" =>$sale_amt, "txn_id"=>$unique_transaction_id, "buyer_email"=>$email));
			}
		}
	}
}
add_action('AHEE__EE_Transaction_Processor__manually_update_registration_statuses','espresso_track_successful_sale_manual', 20, 3);

function espresso_track_successful_sale_gateway( $Transaction, $status_updates ){
    
//throw new Exception("BROKEN");

	if ($Transaction instanceof EE_Transaction) {
		$sale_amt = $Transaction->paid();
		$unique_transaction_id = $Transaction->ID();
		$Primary_Registration = $Transaction->primary_registration();
		if ($Primary_Registration instanceof EE_Registration) {
			$Attendee = $Primary_Registration->attendee();
			if ($Attendee instanceof EE_Attendee) {

				

				$email = $Attendee->email();
				$referrer = $_COOKIE['ap_id'];

				//throw new Exception("Sale amount: ".$sale_amt.", " .
				//	"unique_transaction_id: ".$unique_transaction_id.", " .
				//	"email: ".$email.", " .
				//	"referrer: ".$referrer.", "
				//	, 1);

				do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" =>$sale_amt, "txn_id"=>$unique_transaction_id, "buyer_email"=>$email));
			}
		}
	}
}
add_action('AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment','espresso_track_successful_sale_gateway', 20, 3);

Any help on this would be greatly appreciated.


ds

March 19, 2015 at 6:40 am

forgot to mention the first function using the action AHEE__EE_Transaction_Processor__manually_update_registration_statuses works and appears correctly on the Wp affiliate program.


ds

March 19, 2015 at 10:04 am

Hey sorry for the multple posts, we have actually fixed it. The code works and we have tested it on our site. We will be pushing it to live. Here it is for everyone interested.

https://github.com/ds-festival/event_espresso_4_custom/blob/master/espresso_custom.php


Dean

March 20, 2015 at 4:10 am

Hi,

Sorry for the slow response, but I’m glad you got it resolved and thank you for sharing it!

Viewing 3 reply threads

The support post ‘EE4 and WP Affiliate’ 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