Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

For extra guidance, please see WPBeginner's tutorial on adding custom code.

Dismiss

Description

The wpforms_pro_fields_entry_preview_get_field_value_show_empty filter lets you control whether empty fields are included in the Entry Preview. You can use it to hide fields that have no value so they do not appear in the preview.

Parameters

$show
(bool) (Required) Determines if fields with empty values should be displayed in the Entry Preview. default is true
$field
(array) (Required) Field data.
$form_data
(array) (Required) Form data.

Source

wpforms/pro/includes/fields/class-entry-preview.php

More Information

This filter runs for fields that are empty in the Entry Preview. By default, empty fields are still shown because the $show value is true. If you return false from this filter, the empty field will be hidden from the Entry Preview. You can use this to hide empty fields globally or conditionally for specific fields.

Example

Use this example to hide empty fields in the Entry Preview and also treat Payment Single Item fields with a quantity of zero as empty, so they are removed from the preview as well.

add_filter( 'wpforms_pro_fields_entry_preview_get_field_value_payment-single_field', function( $value, $field, $form_data ) {
    // Single Item fields with Quantity enabled: we check if quantity is zero e.g, $10.00 × 0.
    // This is the exact substring that indicates a quantity of zero bcoz the multiplication sign is an HTML entity.
    $substring_to_check = '× 0';
 
    // We use strpos() for maximum compatibility to check if the substring exists.
    if ( strpos( $value, $substring_to_check ) !== false ) {
        // Return an empty string so the field is considered empty in the preview.
        return '';
    }
	
    // Otherwise, return it unchanged.
    return $value;
 
}, 10, 3 );

add_filter( 'wpforms_pro_fields_entry_preview_get_field_value_show_empty', function( $show, $field, $form_data ) {
    
    // Hide empty fields in Entry Preview.
    return false;
}, 10, 3 );