• Resolved flipty

    (@flipty)


    Hi there, love this plugin. I am trying to have the email notification from a very lengthy order form (for a small farm) include all fields that have a value in them. Is there a way to do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    It’s definitely doable with some custom code. Here’s something I haven’t had the chance to test but should do what you want:

    
    function email_content_all_fields( $content, $email, $form, $fields ) {
        $output = '<table class="af-field-include">';
        
        foreach ( $fields as $field ) {
          if ( empty( $field['value'] ) ) {
            continue;
          }
          
          if ( 'clone' == $field['type'] ) {
            
            foreach ( $field['sub_fields'] as $sub_field ) {
              
              $output .= sprintf( '<tr><th>%s</th></tr>', $sub_field['label'] );
              $output .= sprintf( '<tr><td>%s</td></tr>', _af_render_field_include( $sub_field, $field['value'][ $sub_field['name'] ] ) );
              
            }
            
          } else {
          
            $output .= sprintf( '<tr><th>%s</th></tr>', $field['label'] );
            $output .= sprintf( '<tr><td>%s</td></tr>', _af_render_field_include( $field ) );
          
          }
          
        }
        
        $output .= '</table>';
    
        return $output;
    }
    add_filter( 'af/form/email/content/key=FORM_KEY', 'email_content_all_fields', 10, 4 );
    

    It’s simply the code for {all_fields} but modified to check if the field value is empty first!

    Hope that works!

    Thread Starter flipty

    (@flipty)

    Wow, even if this *does not* work I commend you on your excellent support! I will try it out and report back.

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Haha, I hope it works now! Also, remember to replace FORM_KEY with your actual form key 🙂

    Thread Starter flipty

    (@flipty)

    That worked AMAZINGLY. Thank you!!

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Lovely to hear!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Notification – show only fields with values’ is closed to new replies.