I have a number of checkboxes that indicate the item that is ordered through our online order form system. For each item selected there is a corresponding .pdf file that is stored on our server that should be included in the email.
For instance, they would select three out of five of the checkboxes below and then the three .pdfs that go with those selections are attached to the email.
[checkbox SR-010-01]
[checkbox SR-010-02]
[checkbox SR-010-03]
[checkbox SR-010-04]
[checkbox SR-010-05]
Contact Form 7 allows for files to be attached as a default, but I can't seem to find a way to add them based on whatever selection is made.
Is there maybe a way to use the CF7 file upload system to upload files that already exist locally? There might be a Javascript based solution that way.
sure, use the wpcf7_mail_components filter which allows you to interact with the mail structure before being sent out,
add_filter('wpcf7_mail_components', 'attach_files_based_on_field',10,3);
function attach_files_based_on_field($components, $form, $mail){
//get the form submited data
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data('my-checkbox-field');
//check the values ($data) of your checkbox field
//and decide which file to attach
$components['attachments'][] = '/path-relative-to-wp-content-folder/file.name';
return $components;
}
NOTE: the CF7 plugin will seek files to attach relative to the wp-content folder so you need to give file paths that relative to that folder.