• Resolved selenii

    (@selenii)


    I am trying to use this hook to separate the attribut in the checkboxes by line in the email notification.

    I tried this code, but it is not work. It is right one?

    add_filter('wpcf7_mail_tag_replaced', 'format_chackbox',10,4);function format_chackbox($replaced, $submitted, $is_html, $mail_tag){  //you can check if this is the right field if need be.  if('checkbox_name' != $mail_tag->field_name()) return $replaced;  //$submitted contains the raw submitted data.  //$replaced is the formatted data, you can use either.  $a = explode(',', $replaced);  //check if you have multiple values and the email accepts html (set with the use html checkbox in the mail notification settings).  if(is_array($a) && $is_html){    $replaced = '<ul>'.PHP_EOL;    foreach($a as $v) $replaced .= '<li>'.trim($v).'</li>'.PHP_EOL;    $replaced .= '</ul>'.PHP_EOL;  }  return $replaced;}
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter selenii

    (@selenii)

    Thx for you feedback. I am not so strong in PHP, can you please give me a right code. Thank you very much.

    Thread Starter selenii

    (@selenii)

    Thx, I solved the problem.

    Code in function.php

    add_filter('wpcf7_mail_tag_replaced', 'format_checkbox_webinar', 10, 4);
    function format_checkbox_webinar($replaced, $submitted, $is_html, $mail_tag) {
        if ('Your-Checkbox-Value-Name' === $mail_tag->field_name() && $is_html) {
            $values = explode(',', $replaced);
            if (is_array($values)) {
                $replaced = '<ul>' . PHP_EOL;
                foreach ($values as $value) {
                    $replaced .= '<li>' . trim($value) . '</li>' . PHP_EOL;
                }
                $replaced .= '</ul>' . PHP_EOL;
            }
        }
        return $replaced;
    }
    

    I’ve tried this using WPCode plugin and I’ve tested that the code is executing by doing some echo’s at the top but the function never executes. Should work in WPCode as well right?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Line Breaks in Email the Checkboxes’ is closed to new replies.