Hi,
I build a small function to dynamically change the subject or the recipient, which used to work, but suddenly it doesn’t.
I tested everything and what I found is the unit_tag I use to get the postID didn’t contain the postID. It now lokks like this wpcf7-f13028-o1.
My code:
function customFormRecipient($contactForm){
$submission = WPCF7_Submission::get_instance();
if($submission) {
$unit_tag = $submission->get_meta( 'unit_tag' );
$explode_unit_tag = explode("-", $unit_tag);
// We're on the viewing request form
$postID = str_replace("p", "", $explode_unit_tag[2]);
//... We now have the postID. Go forth and conquer
$altSubject = get_post_meta($postID, 'alt_subject_form_box', true);
$altRecipient = get_post_meta($postID, 'alt_recipient_form_box', true);
// Get the submited form email data.
$mailData = $contactForm->prop('mail');
if ($postID){
if ($altSubject){
// Set the subject
$mailData['subject'] = $altSubject;
}
if ($altRecipient){
// Set the recipient
$mailData['recipient'] = $altRecipient;
}
}
// Update/set the form properties.
$contactForm->set_properties(['mail' => $mailData]);
}
}
add_action('wpcf7_before_send_mail', 'customFormRecipient');
Can anybody tell me what’s wrong and what I could change to retrieve the postID?
Thanks.