Skip Navigation

[Resolved] Add the paypal IPN, order number, and payment date to a notification

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add the PayPal IPN, the WooCommerce Order ID, and the payment date to a Forms email notification.

Solution:
You can create custom placeholders using the cred_body_notification_codes and cred_subject_notification_codes APIs, and access any information about the Order using the post ID from the $_REQUEST superglobal:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
  $order_id = '';
  $completed_date = '';
  $date_format = 'Y-m-d';
  if( isset($_REQUEST['post'][0])) {
    $order_id = $_REQUEST['post'][0];
    $completed_date = date($date_format, get_post_meta($order_id, '_date_completed', true));
  }
  $newPlaceHolders = array(
    '%%ORDER_ID%%' => $order_id,
    '%%COMPLETED_DATE%%' => $completed_date,
  );
 
  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

I'm not sure how the PayPal IPN is stored in the database, but you can use the Order ID to query postmeta as needed.

Relevant Documentation:
https://toolset.com/documentation/user-guides/how-to-use-custom-placeholders-in-cred-notifications/

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Pat 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#911689

Pat

Hello,

I'm using Cred commerce and would like to setup a notification including the following info :

- Paypal IPN (Paypal is the only payment option)
- Date of the Payment payment
- WC Order number

Let me know how I can add these fields in the notification.
Regards
Pat

#911853

Hi Pat, what is the trigger for this notification?

#911865

Pat

Hi Christian,

I think the best would be to trigger as soon as the payment is completed (and Paypal has returned the IPN). I could also use the status modification (from draft to publish) as payment completion is changing the post status.

Regards
Pat

#911958

Okay you can use the cred_body_notification_codes and cred_subject_notification_codes APIs to create your own custom placeholders. I'm not sure how to display the PayPal IPN, but I can show you how to display the WC Order ID and Payment date. If you can tell me how the PayPal IPN is stored in the database for each order, I might be able to figure something out for that too.

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');

function custom_generic_field_notification( $defaultPlaceHolders ) {
  $order_id = '';
  $completed_date = '';
  $date_format = 'Y-m-d';
  if( isset($_REQUEST['post'][0])) {
    $order_id = $_REQUEST['post'][0];
    $completed_date = date($date_format, get_post_meta($order_id, '_date_completed', true));
  }
  $newPlaceHolders = array(
    '%%ORDER_ID%%' => $order_id,
    '%%COMPLETED_DATE%%' => $completed_date,
  );

  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}
#912171

Pat

Hi Christian,

Thanks for your info.
First, I already had a filter "cred_body_notification_codes". So I suppose I need to integrate part of your code inside the previews one, otherwise, I will have 2 different :
return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

Second, in the previews function assigned to the filter, I have placed this condition :
if(($form_id == 13595) OR ($form_id == 13660) OR ($form_id == 13694) OR ($form_id == 5442) OR ($form_id == 7543) OR ($form_id == 13693) OR ($form_id == 5459) OR ($form_id == 29223) OR ($form_id == 29209) OR ($form_id == 13723) OR ($form_id == 32939) OR ($form_id == 13782) OR ($form_id == 36574) OR ($form_id == 13729) OR ($form_id == 36590) OR ($form_id == 13736) OR ($form_id == 36588) OR ($form_id == 38826) OR ($form_id == 38792) OR ($form_id == 29721) OR ($form_id == 29731) OR ($form_id == 38839) OR ($form_id == 40425))

Do you think I can live without (for simplification reason), meaning, the filter will be available for all Creds even if the new placeholder is not needed. My feeling on this is that should not be a issue for Creds that does not need it, but I would prefer have your taughts.

Regards
Pat

#912541

I already had a filter "cred_body_notification_codes". So I suppose I need to integrate part of your code inside the previews one
You can integrate this new code with the old code, or you can create more than one callback function and register both functions separately:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');
add_filter('cred_body_notification_codes', 'other_custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'other_custom_generic_field_notification');
 
function custom_generic_field_notification ... {
}
function other_custom_generic_field_notification ... {
}

I don't think it will be a problem if this code is executed when a different notification is triggered. One way you can simplify the conditional is to use an array of form IDs and then test if the current form_id is in this array. Here's an example:

$form_array = array( 13595, 13660, ... );
if( in_array( $form_id, $form_array ) ) {
  // your code here
}

Update the array of numbers to include all the CRED form IDs you want to target. This makes adding or removing form IDs easier in the future.

#912807

Pat

Hi Christian,

Perfect. Many thanks for your support.
Regards
Pat