How to disable showing custom fields in emails?

There are few filters that you can override to disable displaying of fields in emails:

  • wccf_email_display_user_field_values - Customer/User Fields
  • wccf_email_display_checkout_field_values - Checkout Fields
  • wccf_email_display_order_field_values - Order Fields

All of those filters has "true" as default value, so you just need to send "false" instead, here's the example on Customer Fields:

add_filter('wccf_email_display_user_field_values', '__return_false');

Note that for Customer Fields this filter only works for the fields saved as "User Profile Field". Fields saved as Billing/Shipping are not affected by this filter - will need to use different method to remove those, if needed.

It is also possible to do that conditionally, as there are also values of fields and order id available - as parameters, so you can check something and then disable (or not) the display of those fields (but note that ALL the fields will be switched off in this case).

add_filter('wccf_email_display_user_field_values', 'maybe_disable_wccf_email_display_user_field_values', 10, 3);

function maybe_disable_wccf_email_display_user_field_values($bool, $fields, $order_id) {

// Iterate the fields
foreach ($fields as $key => $field) {

// Get field key
$field_key = $field['field']->get_key();

// Get field label
$field_label = $field['field']->get_label();

// Get field value
$field_value = $field['display_value'];

if ($field_value == 'Some Value') {
return false;
}
}

return $bool;
}

 

Order Fields and Checkout Fields use similar structure and can be changed/disabled in the same way.

 

Have more questions? Submit a request