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
Hi Pat, what is the trigger for this notification?
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
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 );
}
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
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.
Hi Christian,
Perfect. Many thanks for your support.
Regards
Pat