Leon
Leon

Reputation: 141

Add custom tag contact form 7 in email

this is my code, in mail body display: [optional], but not output (in frontend work ok):

Add_action( 'wpcf7_init', 'custom_add_form_tag_clock' );
    
    function custom_add_form_tag_clock() {
        wpcf7_add_form_tag( 'optional', 'custom_clock_form_tag_handler' );
    }
    
    function custom_clock_form_tag_handler( $tag ) {
        global $product;
        
        $modello = $product->get_attribute( 'Optional' );
        
        if  ($modello != ""){
        $optional = explode(",", $modello);
        $html.= '<label>Scegli uno o più optional</label><select id="myFilter" class="multiple_select" multiple>';
        foreach ($optional as &$value) {
            $html.='<option data-size="large" value="'.$value.'">'.$value.'</option>';
        }
        $html.='</select>';
        }
        
    return $html;
    }

The code get atttribute from woocommerce product with a multiple select.

Upvotes: 0

Views: 1761

Answers (2)

Howard E
Howard E

Reputation: 5659

To make your tag show in the email, you either need to add a name attribute to the form tag [optional] and include it as a variable and then update this line:


// Use this if you're using a tag attribute [option tag-name]
$html.= '<label>Scegli uno o più optional</label><select id="myFilter" class="multiple_select" name="'.$tag->name.'" multiple>';


// Use this if you just want it to work with [option]
$html.= '<label>Scegli uno o più optional</label><select id="myFilter" class="multiple_select" name="optional[]" multiple>';

The email will read the "NAME" attribute of the input field or select

Upvotes: 1

Leon
Leon

Reputation: 141

i have used: optional[] and work it!

$html.= '<label>Scegli uno o più optional</label><select id="myFilter" class="multiple_select" name="optional[]" multiple>';

Upvotes: 0

Related Questions