Your cart is currently empty!
Pass affiliate info into submitted form
—
by
I am using affiliates pro and contact form 7 integration. When the form is submitted I want the notification email from contact form 7 to include affiliate information. It doesn’t matter if it is the id, email, or the name. I just need the submitted form to have some identification of the referring affilitate. Thanks
Posted in Affiliates Pro
Comments
10 responses to “Pass affiliate info into submitted form”
Nevermind, I got it. Thank you so much for your help
ok 😉
I decided to use formidablepro forms instead of contact7. Below is the code I am using and am getting the affiliate id just fine. I am trying to figure out what to change to pull up the email instead. If you will notice at the bottom, the new value for field 220 is where I am pulling up the Affiliates Service. Thanks for your help.
class Affiliates_Service {
/**
* Obtain the referring affiliate's id.
* @param string $service by name
* @return int affiliate id or false if none applies
*/
public static function get_referrer_id( $service = null ) {
$affiliate_id = false;
switch ( $service ) {
default :
if ( isset( $_COOKIE[AFFILIATES_COOKIE_NAME] ) ) {
$affiliate_id = affiliates_check_affiliate_id_encoded( trim( $_COOKIE[AFFILIATES_COOKIE_NAME] ) );
}
}
if ( !$affiliate_id ) {
if ( get_option( 'aff_use_direct', true ) ) {
// Assume a direct referral
$affiliate_id = affiliates_get_direct_id();
}
}
return apply_filters( 'affiliates_service_affiliate_id', $affiliate_id, $service );
}
}
add_filter('frm_get_default_value', 'my_custom_default_value', 10, 2);
function my_custom_default_value($new_value, $field){
if($field->id == 220){ //change 220 to the ID of the field
$new_value = $aff_id = Affiliates_Service::get_referrer_id();
$current_aff = affiliates_get_affiliate( $aff_id );
}
return $new_value;
}
Thanks for all your help. But, I cant get this to work.
$email = $current_aff[’email’];
Hi,
I have tested this and looks work fine.
function cf7_email_affiliates_wpcf7_before_send_mail (&$data) {
if ( !class_exists("Affiliates_Service" ) ) {
require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
}
$aff_id = Affiliates_Service::get_referrer_id();
$current_aff = affiliates_get_affiliate( $aff_id );
if ($current_aff !== null) {
$data->posted_data['your-message'] .= "Affiliate: " . $aff_id . "-" . $current_aff['email'];
}
}
add_action("wpcf7_before_send_mail", "cf7_email_affiliates_wpcf7_before_send_mail");
If your message field has another name, you must change “your-message”.
cheers
what would I need to change if I wanted to get the email of the affiliate instead of the id?
Hi,
you can get the email:
$email = $current_aff['email'];
If you need get another data, have a look to affiliates_get_affiliate function.
cheers
Nevermind. Had a character off. Worked like a charm, Thanks a ton!
ok. thanks for your input antonio. I used the get affiliate code but it broke somewhere. here is what i am getting.
Fatal error: Class ‘Affiliates_Service’ not found in /home/content/h/a/l/halesmith/html/wp-content/themes/memorable/functions.php on line 44
Hi,
you could use “wpcf7_before_send_mail” hook. Here you have more information.
To get the affiliate, you can use (more information on Affiliates Documentation):
$aff_id = Affiliates_Service::get_referrer_id();
$current_aff = affiliates_get_affiliate( $aff_id );
cheers