Stopping emails until after payment completed – trouble

Hi I added the following code to a child them of headway with the open php in front of it and changed the form id to my form id of “12″

to try to prevent emails from being sent out before payment completed and registering people who have not paid and it did not work.

 

i followed the headway tutorial for creating a child them and uploaded and installed it,

 

the child theme contained a css file and a functions.php that included the following code again with my form id on it of 12 wher e it says 7, and the open php marker at the beginning.

add_filter(‘frm_to_email’, ‘stop_the_email’, 20, 3 );
function stop_the_email($emails, $values, $form_id){
if($form_id == 7){ //change 5 to the ID of your form
if(isset($_POST) and ((isset($_POST['payment_completed']) and $_POST['payment_completed']) or (isset($_POST['action']) and $_POST['action'] == ‘send_email’)))
return $emails;
else
$emails = array();
}
return $emails;
}

//Trigger the email to send after a payment is completed:
add_action(‘frm_payment_paypal_ipn’, ‘send_email_now’);
function send_email_now($vars){
if(!$vars['pay_vars']['completed']) //only send the email if payment is completed
return;

global $frmdb;
$entry_id = $vars['payment']->item_id;
$form_id = $frmdb->get_var($frmdb->entries, array(‘id’ => $entry_id), ‘form_id’);
$_POST['payment_completed'] = true; //to let the other function know to send the email
FrmProNotification::entry_created($entry_id, $form_id);
}

 

do you see anything wrng her e i am stlil getting emails immediately, before even touching the paypal window.

 

also if you had many forms how would this change the code?

 

 

First, you'll need to confirm that your functions file is getting used. You can do so by adding some text or something at the very top.

Using the same function for multiple forms is a basic php edit.
if($form_id == 7 or $form_id == 8){

Please hire a developer if you are not comfortable with PHP.

Topic closed.