Viewing 1 replies (of 1 total)
  • Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    To modify an email after the form is submitted, you’ll want to utilize the wpcf7_before_send_mail action. For example:

    function au_add_post_tag_to_form( $contact_form, $abort, $submission ) {

    // Get the post id of the page that the form was submitting on,
    // assuming this is the post with the tag you want to use
    $post_id = intval(trim(sanitize_text_field($_POST['_wpcf7_container_post'])));

    // Validate POST & ACF functionality to avoid errors
    if($post_id && function_exists('get_field')) {

    // Get the ACF value with your selector
    // https://www.advancedcustomfields.com/resources/get_field/
    $tag = get_field('selector', $post_id);

    // Get the mail property
    $mail = $contact_form->prop('mail');

    // Add ACF content to the email body
    $mail['body'] .= $tag;

    // Update email object with modified body content
    $contact_form->set_properties( array('mail' => $mail) );
    }
    }
    add_filter('function au_add_post_tag_to_form( $contact_form, $abort, $submission ) {

    // Get the post id of the page that the form was submitting on,
    // assuming this is the post with the tag you want to use
    $post_id = intval(trim(sanitize_text_field($_POST['_wpcf7_container_post'])));

    // Validate POST & ACF functionality to avoid errors
    if($post_id && function_exists('get_field')) {

    // Get the ACF value with your selector
    // https://www.advancedcustomfields.com/resources/get_field/
    $tag = get_field('selector', $post_id);

    // Get the mail property
    $mail = $contact_form->prop('mail');

    // Add ACF content to the email body
    $mail['body'] .= esc_html($tag);

    // Update email object with modified body content
    $contact_form->set_properties( array('mail' => $mail) );
    }
    }
    add_filter('wpcf7_before_send_mail', 'au_add_post_tag_to_form', 10, 3);

    Since you are inserting an ACF date, you might even want to put something like [ACF DATE] in your mail template and then replace $mail['body'] .= esc_html($tag); with $mail['body'] = str_replace('[ACF DATE]', esc_html($tag), $mail['body']); so that the date is inserted in that custom placeholder.

    And if the date isn’t formatted correctly, be sure to modify the Return Format in your ACF settings to the format you want to use.

Viewing 1 replies (of 1 total)
  • The topic ‘custom ACF field in Contact Form 7 email’ is closed to new replies.