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.

Creating the form

To begin, we’ll create a payment form with Payment Fields. If you need assistance with this, please check out this documentation.

create a payment form and add your payment fields

Adding the snippet

Now it’s time to add the snippet to your site.

If you need help with where and how to add snippets to your site, please check out this tutorial.

/*
 * 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 the form or field ID, please review this documentation.

using this snippet you can hide the item price from email notifications

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.