How to hide orders containing products from specific category on my account page - Hack The Tech - Latest News related to Computer and Technology

logo

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, August 6, 2023

demo-image

How to hide orders containing products from specific category on my account page

How can I get completed orders of the current user containing products from a specific category and hide these orders from the list? I've got in an awful mess...

add_filter( 'woocommerce_my_account_my_orders_query', 'hide_orders_from_my_account', 10, 1 );
function hide_orders_from_my_account( $args ) {
    $customer_order = array(
    'customer_id' => $user_id,
    'limit' => -1,
    'post_status' => array_keys( wc_get_order_statuses() ),  'post_status' => array( 'completed'),
    );
    $orders = wc_get_orders($customer_order);
    $product_category_terms = array('like');
    if ( has_term( $product_category_terms, 'product_cat', $item->get_product_id() ) ) {    
    unset( $status['completed'] );
    $args['post_status'] = array_keys( $status );
    return $args;
   }
}


source https://stackoverflow.com/questions/76843199/how-to-hide-orders-containing-products-from-specific-category-on-my-account-page

No comments:

Post a Comment