WordPress ajax call with add_filter
-
I have a WordPress function that works exactly how I want. The function below changes the email recipient in Contact Form 7 to [email protected]. Now I need to use ajax to update the email recipient to a dynamic value.
function wpcf7_dynamic_email_field($args) {
if(!empty($args[‘recipient’])) {
$args[‘recipient’] = str_replace(‘%admin%’, ‘[email protected]’, $args[‘recipient’]);
return $args;
}
return false;
}
add_filter(‘wpcf7_mail_components’, ‘wpcf7_dynamic_email_field’);
Here’s my ajax call. I do not know how to tell the ajax call to initiate the wpcf7_dynamic_email_field() function. Can that be done?$.ajax({
url: ajaxurl, // or example_ajax_obj.ajaxurl if using on frontend
data: {
‘action’: ‘update_team_page_contact_form’,
’emailAddress’ : emailAddress
},
success:function(data) {
// This outputs the result of the ajax request
console.log(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
- The topic ‘WordPress ajax call with add_filter’ is closed to new replies.