• Resolved cgcomunicazione

    (@cgcomunicazione)


    “Exclude lines with blank mail-tags from output” Is not working with toggle fields in Smart Grid Design extension.
    How can it be fixed?

    Many thaks for your support!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cgcomunicazione

    (@cgcomunicazione)

    I solved it with this function:

    <span style="font-size: 12.8px;">function cf7_exclude_empty_fields($contact_form) {
        // Ottieni l'oggetto della mail
        $submission = WPCF7_Submission::get_instance();
    
        if ($submission) {
            // Ottieni i dati inviati
            $posted_data = $submission->get_posted_data();
    
            // Ottieni l'oggetto della mail
            $mail = $contact_form->prop('mail');
    
            // Filtra i campi vuoti
            $filtered_mail_body = array_filter(explode("\n", $mail['body']), function($line) use ($posted_data) {
                foreach ($posted_data as $key => $value) {
                    if (strpos($line, "[{$key}]") !== false && empty(trim($value))) {
                        return false; // Esclude il campo vuoto
                    }
                }
                return true;
            });
    
            // Unisci nuovamente le linee filtrate
            $mail['body'] = implode("\n", $filtered_mail_body);
    
            // Imposta la mail modificata
            $contact_form->set_properties(array(
                'mail' => $mail
            ));
        }
    }
    add_action('wpcf7_before_send_mail', 'cf7_exclude_empty_fields');
    </span>
    Plugin Author Aurovrata Venet

    (@aurovrata)

    Nice! Thanks for posting your answer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude lines with blank mail-tags from output is not working with toggle fields’ is closed to new replies.