skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    i have used: optional[] and work it!

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

  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search