[ad_1]
I think I have it figured out, or at least one solution that works for me.
In case anyone else wants to prevent a custom order item meta from appearing in an invoice and packing slip, you can add the following code snippet to your child theme’s functions.php:
add_filter('woocommerce_order_item_get_formatted_meta_data', 'unset_specific_order_item_meta_data', 10, 2);
function unset_specific_order_item_meta_data($formatted_meta, $item){
/*
// Only on emails notifications
if(is_admin() || is_wc_endpoint_url()) {
return $formatted_meta;
}
*/
foreach($formatted_meta as $key => $meta){
if(in_array($meta->key, array('<name of your order item meta to remove>'))) {
unset($formatted_meta[$key]);
}
}
return $formatted_meta;
}
Just replace <name of your order item meta to remove> with a comma-separated list (in single quotes) of the order item meta(s) names you want to remove. This is a WordPress function, and will also remove the order item meta from notification emails.
If you want the order item meta to appear in admin-generated PDF invoices and admin email notifications, you can try un-commenting this section:
if(is_admin() || is_wc_endpoint_url()) {
return $formatted_meta;
}
I haven’t tested that part, because I wanted the item meta hidden everywhere.
Using this solution is perfect for my needs, because it doesn’t delete the custom order item meta name/value, it just doesn’t include them in the formatted output.
I found the answer here, so thanks to LoicTheAztec.
