In this tutorial, you will learn how to hide specific product attributes from WooCommerce order confirmation emails. There are usually two ways used for this purpose. The first way is to change the email template. The second way is to write a short snippet that will solve this problem. In this article, I will explain how to do this via snippet. This code should be added to the functions.php file of your child theme.
How to Determine the Name of an Attribute in WooCommerce
First you need to define the correct attribute name. To do this, go to Products>All products>Product settings>Attributes. Scroll down to the Product data section and click on the Attributes tab.
Note the attribute name you are interested in. For example, if you have an attribute called “Color”, it might have a slug like color. After that, replace the attribute name in my snippet and make a new test order. If you got the attribute name correct, you’re done!
// Remove attributes from woo emails
add_filter('woocommerce_order_item_get_formatted_meta_data', 'remove_item_meta_from_emails', 10, 2);
function remove_item_meta_from_emails($formatted_meta, $item) {
// Keys of the attributes to remove
$keys_to_remove = array('color');
foreach ($formatted_meta as $key => $meta) {
if (in_array($meta->key, $keys_to_remove)) {
unset($formatted_meta[$key]);
}
}
return $formatted_meta;
}
Leave a Reply