Get ACF custom fields before sending mail

  advanced-custom-fields, php, wordpress

I have a wordpress and use Advanced Custom Fields to create my custom fields.

I use it in my wordpress article to generate dynamic contents. I create a dynamic dropdown in my contact form 7 with CF7 Smart Grid Design Extension.

I need to add a fields depending of the answer of my user in the mail. So I use the hook : wpcf7_posted_data to change data before sending the mail. It’s worked, I can change data.

So much exposition 🙂

My problem is, I can’t get data from my custom fields in this hook (return blank) (line3).

How can I get data from my custom fields from inside this hook ?

function action_wpcf7_posted_data($array)
{
    $ses = get_field('date');
    $ses = $ses['body'];
    $sesCount = count($ses["body"]);
    $a = "";
    for ($i = 0; $i <= $sesCount; $i++) {
        if ($ses[$i][1]["c"] == $array['upcoming-gigs']) {
            $array['session_date'] = $ses[$i][0]["c"];
        }
    }

    $array['Nom & Prénom'] = get_field('duree');
    unset($array['name']);

    $array['E-mail'] = $array['email'];
    unset($array['email']);

    $array['Téléphone'] = $array['tel'];
    unset($array['tel']);

    $array['Profession'] = $array['job'];
    unset($array['job']);

    $array['Session'] = $array['upcoming-gigs'];
    unset($array['upcoming-gigs']);

    unset($array['privacy']);

    return $array;
}

add_filter('wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1);

Thanks.

Source: Ask PHP

LEAVE A COMMENT