Home / Admin / How to Hide Zero Quantity Items in Dropdown Payment Field Notifications
Duplicate Snippet

Embed Snippet on Your Site

How to Hide Zero Quantity Items in Dropdown Payment Field Notifications

This snippet hides items with zero quantities from your WPForms notification emails when using payment fields

<10
Code Preview
php
<?php
/**
 * Hiding Zero Quantity Items in Email Notifications for Payment Fields
 *
 * @link https://wpforms.com/developers/how-to-hide-zero-quantity-items-in-dropdown-payment-field-notifications
 */
add_filter('wpforms_entry_email_data', function ($fields, $entry, $form_data) {
    foreach ($fields as $field_id => $field) {
        // Adjust to handle 'payment-single', 'payment-select', or any other types
        if (
            isset($form_data['fields'][$field_id]['type']) && 
            in_array($form_data['fields'][$field_id]['type'], ['payment-select', 'payment-single'])
        ) {
            $quantity = isset($field['quantity']) ? (int) $field['quantity'] : 0;
            if ($quantity == 0) {
                unset($fields[$field_id]);
            }
        }
    }
    return $fields;
}, 10, 3); 

Comments

Add a Comment