<?php
/**
* conditionally send notification emails based on permit type
*
* @link https://advancedforms.github.io/filters/af-form-email-recipient/
* @link https://advancedforms.github.io/filters/af-form-email-content/
*
*/
function filter_email_content( $content, $email, $form, $fields ) {
// get permit type from application and check name of email
$permit_type = af_get_field( 'wd_permit_application_type' );
$email_name = $email['name'];
$email_value = print_r( $email );
// check if permit type and email name match
if( $email_name == 'User Notice' ) {
// emtpy out content
$content = '';
// loop over permit types user has set in "Site Options"
if ( have_rows( 'wd_options_permits', 'option' ) ) :
while ( have_rows( 'wd_options_permits', 'option' ) ) : the_row();
// get permit name set for each options
$permit_name = get_sub_field( 'wd_permit_name' );
// compare permit name in "Site Options" with permit name from application and attach content if they match
if( $permit_type['label'] == $permit_name ) {
$content .= get_sub_field( 'email_notification_content' );
}
endwhile;
endif;
}
return $content;
}
add_filter( 'af/form/email/content/key=form_5f1af8ee58176', 'filter_email_content', 10, 4 );