From 027e195aac0d92584f19f659d7f6622ee807f7eb Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Fri, 21 Apr 2023 18:12:09 -0600 Subject: [PATCH] do not send emails to on hold or do not email contacts --- .../CRM/Contribute/Form/Contribution.tpl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 87157abdfb..f22f9d5d31 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -385,8 +385,23 @@ function checkEmail() { var data = $("#contact_id", $form).select2('data'); if (data && data.extra && data.extra.email && data.extra.email.length) { - $("#email-receipt", $form).show(); - $("#email-address", $form).html(data.extra.email); + CRM.api4('Email', 'get', { + select: ["on_hold"], + where: [["contact_id", "=", data.id], ["is_primary", "=", true]], + chain: {"contact_do_not_email":["Contact", "get", {"where":[["id", "=", data.id]], "select":["do_not_email"]}]} + }).then(function(emails) { + if (!emails[0]['on_hold'] && !emails[0]['contact_do_not_email'][0]['do_not_email']) { + $("#email-receipt", $form).show(); + $("#email-address", $form).html(data.extra.email); + } + else { + CRM.alert(ts("No email receipt can be sent as the contact's primary email address is on hold or they are set to do not email."), ts("Cannot send email receipt")); + $("#email-receipt", $form).hide(); + } + }, function(failure) { + $("#email-receipt", $form).show(); + $("#email-address", $form).html(data.extra.email); + }); } else { $("#email-receipt", $form).hide(); -- 2.25.1