Change components based on form mail 1 or 2 templates
-
Can I change components based on form mail 1 or 2 templates in the
wpcf7_mail_components
hook
How can I target these mail templates inside this function?
Currently I’m sending two modified emails with the same information but they need to be different.class Form { private $contact_form_7_ids = array(); private $posted_data = array(); public function wpcf7_mail_components( $components, $form, $mail_object ) { $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $this->posted_data = $submission->get_posted_data(); } if ( !in_array( $form->id(), $this->contact_form_7_ids ) ) { return $components; } // Change components based on form mail 1 or 2 templates // How can I target these mail templates inside this function? if ( 'mail' ) { $response_subject = $this->posted_data['subject_custom']; $response_body = $this->posted_data['email_body_custom']; $response_button = $this->posted_data['button_custom_url']; $email_recipients = $this->posted_data['email']; } if ( 'mail_2' ) { $email_recipients = $this->posted_data['recipent_contact']; } if ( $response_subject ) { $components['subject'] = $response_subject; } if ( $response_body ) { $components['body'] = $response_body; } if ( $response_button ) { $components['body'] .= $response_button; } if ( $email_recipients ) { $components['recipient'] = $email_recipients; } else { $components['recipient'] = '[email protected]'; } return $components; } private function init() { add_filter( 'wpcf7_mail_components', [ $this, 'wpcf7_mail_components' ], 10, 3 ); } }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Change components based on form mail 1 or 2 templates’ is closed to new replies.