I would like to hide one product from my order notification (which comes via email)
I took this code as a basis, it works. This code hides certain products in the checkout page using product IDs:
function filter_woocommerce_cart_item_visible( $true, $cart_item, $cart_item_key ) {
// The targeted product ids
$targeted_ids = array( 5500, 5499, 5498 );
// Computes the intersection of arrays
if ( array_intersect( $targeted_ids, array( $cart_item['product_id'], $cart_item['variation_id'] ) ) ) {
$true = false;
}
return $true;
}
add_filter( 'woocommerce_cart_item_visible', 'filter_woocommerce_cart_item_visible', 10, 3 );
I tried changing the code to hide this product in order notifications (via order item), but this modified code is throwing an error. Here is the code:
function hide_product_from_order( $true, $order_item, $order_item_key ) {
// The targeted product ids
$targeted_ids = array( 5500, 5499, 5498 );
// Computes the intersection of arrays
if ( array_intersect( $targeted_ids, array( $order_item['product_id'],$order_item['variation_id'] ) ) ) {
$true = false;
}
return $true;
}
add_filter( 'woocommerce_order_item_visible', 'hide_product_from_order', 10, 3 );
They are some mistakes in your code, try the following revised code:
Code goes in functions.php file of your active child theme (or active theme). It should work now.