My intention is to hide orders that contains a specific product id (5). This in the WooCommmerce "My account" orders table
What I have done are the steps as described in the /myaccount/orders.php
template file. Namely copied the file to my theme folder.
(mytheme/woocommerce/myaccount/orders.php.)
There I replaced
<tbody>
<?php
foreach ( $customer_orders->orders as $customer_order ) {
$order = wc_get_order( $customer_order ); // phpcs:ignore
WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count() -
$order->get_item_count_refunded();
?>
<tr class="woocommerce-orders-table__row
woocommerce-orders-table__row--status-<?php echo esc_attr(
$order->get_status() ); ?> order">
...
</tr>
<?php
}
?>
</tbody>
With
<tbody>
<?php
foreach ( $customer_orders->orders as $customer_order ) {
$order = wc_get_order( $customer_order ); // phpcs:ignore
WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count() -
$order->get_item_count_refunded();
foreach( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
if ( $product_id != 5 ) {
?>
<tr class="woocommerce-orders-table__row
woocommerce-orders-table__row--status-<?php echo esc_attr(
$order->get_status() ); ?> order">
...
</tr>
<?php
}
}
}
?>
</tbody>
Although this has no error messages, it does not produce the desired result.
Can someone give some advice? oh, and if there is a solution via hooks instead of overwriting the template file I'd really appreciate it.