Contact Form 7 – PayPal & Stripe Add-on Pro – Dynamic Mail Attachments

This code can be used as a template if you want to dynamically attach files to emails. This works with the “send email after payment” feature.

  1. Put subscribers_only: true into your forms Additional settings tab.
  2. This goes on your functions.php page:

$user_id = ‘0’;

function dynamic_attachments_get_user_id($post_id) {

global $user_id;

$post = get_post($post_id);

return $user_id = $post->post_author;

}

add_action(‘cf7pp_payment_successful_pre_send_email’, ‘dynamic_attachments_get_user_id’, 10, 2);

 

function dynamic_attachments($components) {

global $user_id;

$file = wp_upload_dir()[‘path’] . ‘/’ . $user_id . ‘.pdf’;

$components[‘attachments’][] = $file;

return $components;
}
add_action(‘wpcf7_mail_components’, ‘dynamic_attachments’);


Rate this Article