Reply To: Send notification email when changing in backend

Home Forums Quform WordPress Send notification email when changing in backend Reply To: Send notification email when changing in backend

#36586
fbxac
Participant

Hi,

Thanks for the update. This worked, however, it only worked for 1 configured option. I am choosing a radio option with the following:

Approve
Reject
Waitlist

Below is my code. Am I supposed to duplicate the code 3x (one for each class ie: Approve, Reject, Waitlist)


<?php

/*
* Plugin Name: Quform Approval Automation
* Description: Send auto notifications when marking applications as Approve, Reject or Waitlist
* Version: 1.0
*/

// Paste in your custom code below

##APPROVAL EMAIL

add_filter('quform_entry_post_set_entry_id_1', function (array $result, Quform_Form $form) {
// Look up old field value
global $wpdb;
$elementId = '1_78';
$notificationId = '1_3';

list(, $eid) = explode('_', $elementId);

$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);

if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}

return $result;
}, 10, 2);

##REJECTED EMAIL

add_filter('quform_entry_post_set_entry_id_1', function (array $result, Quform_Form $form) {
// Look up old field value
global $wpdb;
$elementId = '1_78';
$notificationId = '1_4';

list(, $eid) = explode('_', $elementId);

$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);

if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}

return $result;
}, 10, 2);

##WAITLIST EMAIL

add_filter('quform_entry_post_set_entry_id_1', function (array $result, Quform_Form $form) {
// Look up old field value
global $wpdb;
$elementId = '1_78';
$notificationId = '1_5';

list(, $eid) = explode('_', $elementId);

$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);

if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}

return $result;
}, 10, 2);

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy