Sending Data Sharing Email to Project Lead. #7410
Unanswered
KyleIrving
asked this question in
Developer Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
We need your help.
Objective:
We are developing a plugin for GiveWP that allows donors to set data sharing options and then email a project lead/volunteer with the information.
Current Progress:
We have successfully created meta boxes on the GiveWP donation form:
Issues We Are Facing:
Email Template Registration:
Our problem is that we have been unable to register the template.
Can you help?
This is code we have tried so far for your reference.
`// Add a new email
function my_custom_email($emails) {
$emails['my_custom_email'] = array(
'id' => 'my_custom_email',
'label' => __( 'My Custom Email', 'give' ),
'message' => 'give_get_option_data_sharing_email_setting',
'subject' => give_get_option( 'data_sharing_email_subject', __( 'New Custom Email', 'give' ) ),
);
return $emails;
}
add_filter( 'give_emails', 'my_custom_email' );
// Callback function to get email content
function give_get_option_data_sharing_email_setting() {
return give_get_option( 'data_sharing_email_setting', __( 'This is a custom email.', 'give' ) );
}
// Add a new email template
function my_custom_email_template($templates) {
$templates['data_sharing_email'] = __( 'Data Sharing Email for Project Leads and Volunteers', 'give' );
return $templates;
}
add_filter( 'give_email_templates', 'my_custom_email_template' );
// Use the custom email template for the new email
function my_custom_email_template_option($template, $email_id) {
if ( 'my_custom_email' === $email_id ) {
$template = 'data_sharing_email';
}
return $template;
}
add_filter( 'give_email_template', 'my_custom_email_template_option', 10, 2 );
// Add sections for the new email template
function my_custom_email_template_sections($sections) {
$sections['data_sharing_email'] = __( 'Data Sharing Email', 'give' );
return $sections;
}
add_filter('give_get_sections_emails', 'my_custom_email_template_sections', 10, 1);
// Add settings for the new email template
function my_custom_email_template_settings($settings) {
$current_section = give_get_current_setting_section();
if ( 'data_sharing_email' === $current_section ) {
$settings = array(
array(
'id' => 'give_title_data_sharing_email',
'type' => 'title',
),
array(
'id' => 'data_sharing_email_subject',
'name' => __( 'Email Subject', 'give' ),
'desc' => __( 'The subject line for the data sharing email.', 'give' ),
'type' => 'text',
'default' => 'Data Sharing Information',
),
array(
'id' => 'data_sharing_email_setting',
'name' => __( 'Data Sharing Email Setting', 'give' ),
'desc' => __( 'This is a setting for the data sharing email.', 'give' ),
'type' => 'textarea',
'default' => 'Default value',
),
array(
'id' => 'give_sectionend_data_sharing_email',
'type' => 'sectionend',
),
);
}
return $settings;
}
add_filter('give_get_settings_emails', 'my_custom_email_template_settings');
// Render the new email template
function my_custom_email_template_content($content, $args) {
if ( 'data_sharing_email' === give_get_option('email_template') ) {
// Define your email content here
$content = "
" . __( 'Data Sharing Information', 'give' ) . "";
$content .= "
" . __( 'Thank you for your donation. Here are the details of your data sharing preference:', 'give' ) . "
";$content .= "
" . give_do_email_tags('{data_sharing}', $args['payment_id']) . "
";$content .= "
" . __( 'Best regards,', 'give' ) . "
";$content .= "
" . __( 'Your Organization', 'give' ) . "
";}
return $content;
}
add_filter('give_email_message', 'my_custom_email_template_content', 10, 2);
// Add a new email tag
function my_custom_email_tag($tags) {
$tags[] = array(
'tag' => 'data_sharing',
'description' => __( 'Data Sharing Preference', 'give' ),
'function' => 'my_custom_email_tag_function',
);
return $tags;
}
add_filter( 'give_email_tags', 'my_custom_email_tag' );
// Define the function for the new email tag
function my_custom_email_tag_function($payment_id) {
$data_sharing = give_get_meta($payment_id, 'data_sharing_preference', true);
return $data_sharing ? $data_sharing : 'N/A';
}
// Send email to project lead/volunteer
function my_custom_send_email($payment_id) {
$donation = give_get_payment($payment_id);
$project_lead_email = give_get_meta($donation->ID, '_give_project_lead_email', true);
$data_sharing_preference = give_get_meta($donation->ID, 'data_sharing_preference', true);
// Only send email if data sharing preference is not 'do_not_share'
if ($project_lead_email && $data_sharing_preference != 'do_not_share') {
$message = give_get_option('data_sharing_email_setting');
$message = give_do_email_tags($message, $payment_id);
$subject = give_get_option('data_sharing_email_subject');
wp_mail($project_lead_email, $subject, $message);
}
}
add_action('give_complete_donation', 'my_custom_send_email');`
Beta Was this translation helpful? Give feedback.
All reactions