How to Hide the Item Price Value in the Email Notifications

Introduction

Would you like to hide the Item Price from the email notifications? You may need to hide either the total or just the item price or even another field from your email notifications. Using a small PHP snippet you can easily exclude the price from the notification.

Setup

Simply copy this code snippet to your site.

/*
 * Hide the price from notifications
 *
 * @link https://wpforms.com/developers/how-to-hide-the-item-price-value-in-the-email-notifications
 *
 */

function wpf_email_field_value( $value, $field, $form_data, $context) {
    
    if ( 'email-html' === $context ) {
	
        // If the form ID is 364 AND the field ID is 19 remove the value from the email notification	
        if ( 364 == $form_data['id'] && 19 == $field['id'] ) {
            return $field['value'] = '';
        }
    }

    return $value;
}
add_filter( 'wpforms_html_field_value', 'wpf_email_field_value', 15, 4 );

You’ll need to update the code above so that it matches the correct form ID (364) and the correct field id (19). If you need assistance with finding these ID numbers, please review this documentation.

How the price is hidden from the email notification

And that’s all you need! Would you like to customize the email template header when sending your emails? Take a look at our article on How to Customize the Styles on the Email Template.

Filter Reference: wpforms_html_field_value

FAQ

Q: Can you use this to hide a Hidden Field from the email notification?

A: Absolutely! You would just change the 19 == $field[‘id’] to match the ID of the Hidden Field.

Q: Can I hide multiple fields with this?

A: Of course! So to hide more than one field, you would just need to use a PHP or statement. The or statement is just two pipelines in your code. See the example below.

/*
 * Hide the price from notifications
 *
 * @link https://wpforms.com/developers/how-to-hide-the-item-price-value-in-the-email-notifications
 *
 */

function wpf_email_field_value( $value, $field, $form_data, $context) {
    
    // If you are sending HTML emails run this snippet
    if ( 'email-html' === $context ) {

        // And if the form ID is 364 AND the field ID is 19 OR the form ID is 364 AND the field ID is 18
        // remove the value from the email notification	 		
        if ( 364 == $form_data['id'] && 19 == $field['id'] || 364 == $form_data['id'] && 18 == $field['id']) {
            return $field['value'] = '';
        }
    }

    return $value;
}
add_filter( 'wpforms_html_field_value', 'wpf_email_field_value', 15, 4 );

You can also do the same with the or statement and group multiple form IDs as well as multiple field IDs.