Title: Hide empty fields in emails?
Last modified: July 1, 2020

---

# Hide empty fields in emails?

 *  Resolved [Dennis Dallau](https://wordpress.org/support/users/yorlinqnl/)
 * (@yorlinqnl)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/hide-empty-fields-in-emails/)
 * I know when I use {fields} in the emails body I will probably get only the fields
   that are actually filled in… But I don’t like the lay-out so I call each field
   separately.
 * Bu the problem now is, is when I field is empty, the label still is shown in 
   the email body.
 * I was wondering… Is there an IF STATEMENT possible within the email action?
 * if (empty(field_x) then hide the field…

Viewing 1 replies (of 1 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/hide-empty-fields-in-emails/#post-13066180)
 * Hello,
 * Thanks for the feedback. There’s no conditional template tag available right 
   now. You can create your own output tho, and use it in an “E-mail Action”.
 * To do so, create a new “Custom Action”, right before the “E-mail” action. Let’s
   call it “email-output”. Use the custom code in the “Advanced Tab” to create your
   own `query_var` which will output exactly the fields you want. In your case, 
   something like this:
 *     ```
       add_action('acfe/form/submit/email-output', 'my_form_email_output', 10, 2);
       function my_form_email_output($form, $post_id){
   
           // Start buffer
           ob_start();
   
           ?>
   
           <?php 
   
           // Retrive my_field user input
           if(get_field('my_field')){ ?>
   
               Field: <?php echo get_field('my_field'); ?><br />
   
           <?php } ?>
   
           <?php 
   
           // Retrive my_field_2 user input
           if(get_field('my_field_2')){ ?>
   
               Field 2: <?php echo get_field('my_field_2'); ?><br />
   
           <?php } ?>
   
           ...
   
           <?php
   
           // Retrieve buffer
           $output = ob_get_clean();
   
           // Set Query var to be used in a latter action using {query_var:email-output}
           set_query_var('email-output', $output);
   
       }
       ```
   
 * As you can see, in the action I use `set_query_var()` function to set the data
   I want to display. Then in the “E-mail Action” I retrieve it using `{query_var:
   email-output}`.
 * See screenshot: [https://i.imgur.com/j99gI8m.png](https://i.imgur.com/j99gI8m.png)
 * Hope it helps!
 * Regards.

Viewing 1 replies (of 1 total)

The topic ‘Hide empty fields in emails?’ is closed to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

## Tags

 * [emails](https://wordpress.org/support/topic-tag/emails/)
 * [if statement](https://wordpress.org/support/topic-tag/if-statement/)
 * [output](https://wordpress.org/support/topic-tag/output/)

 * 1 reply
 * 2 participants
 * Last reply from: [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/hide-empty-fields-in-emails/#post-13066180)
 * Status: resolved