Manipulate email content

Hi, is it possible to modify the content of an email before sending?

Unfortunately I have a fairly complex use case.

in short:
Form = CPT (Products) + Number field.
After sending, the quantity of products will be adjusted. (work as needed)
after that a Post in CPT “ordres” will be created. (work as needed)

I would like the items ordered to be shown in the email. (no way found)

In the form, I only have quantities that are iterated over a CPT and the ID contains the post ID. I get the title {Post_title} and pass it to the label.

I thought I could create a hidden field in the form.
Assemble an HTML in the action “before_submit” and pass it to the field as a value.

but unfortunately it is not shown to me.

$produkt_details = "";
        foreach ($form_data as $key => $value) {
            if (strpos($key, 'form-field-pid-') !== false && !empty($value)) {
                $product_id = str_replace('form-field-pid-', '', $key);
                if (get_post_type($product_id) === 'produkt') {
                    $product_name = get_the_title($product_id);
                    $row = [
                        'produkt_id'   => $product_id,
                        'produkt_name' => $product_name,
                        'menge'        => $value,
                    add_row('produkte', $row, $order_post_id);
                   $produkt_details .= "<p><b>" . $product_name . " Menge: " . $value . "</b></p>";

        $form_data['bestellte-positionen'] = $produkt_details;

@Daniele mby you can support me in this case?

ok i solved over JS and a hidden field

document.addEventListener('DOMContentLoaded', function() {
    const inputs = document.querySelectorAll('input[name^="form-field-pid-"]');

    function updateHiddenField() {
        let summary = '';
        inputs.forEach(input => {
            const label = document.querySelector(`label[for="${}"]`);
            if (input.value > 0 && label) {
                summary += `<div>${label.innerHTML}: ${input.value}</div>`;
        const hiddenInput = document.querySelector('input[name="form-field-bestellte-positionen"]');
        if (hiddenInput) {
            hiddenInput.value = summary.replace(/"/g, '&quot;');  // Ersetze Anführungszeichen für korrekte HTML-Attribut-Codierung

    inputs.forEach(input => {
        input.addEventListener('input', updateHiddenField);
1 Like