skip to Main Content

Inspired by the thread ‘Hiding order status in My Account recent orders list page’
I tried to hide orders with status (Pending Payment) on the ‘My Account’ page.

I modified the code slightly, but I can’t get it to work.

add_filter('woocommerce_my_account_my_orders_actions', 'custom_removing_order_status_pending_payment', 10, 1);

function custom_removing_order_status_pending_payment( $order ){
    unset($order['wc-pending']);
    return $order;
}

I really appreciate any help. Thank you.

2

Answers


  1. Right now you are using the woocommerce_my_account_my_orders_actions filter which will let you filter the buttons in the ‘Action’ column on the ‘My Account’ page.

    If you want to filter out certain order statuses from the order list you will have to use the woocommerce_my_account_my_orders_query filter.

    add_filter( 'woocommerce_my_account_my_orders_query', 'unset_pending_payment_orders_from_my_account', 10, 1 );
    function unset_pending_payment_orders_from_my_account( $args ) {
        $statuses = wc_get_order_statuses();    
        unset( $statuses['wc-pending'] );
        $args['post_status'] = array_keys( $statuses );
        return $args;
    }
    
    Login or Signup to reply.
  2. The accepted answer is mostly, OK, however, it relies on WooCommerce saving Orders as a WordPress custom post type, and there’s been for a while a conversation about moving orders to their own custom table to improve performance and scalability of WooCommerce-powered stores.

    As a general rule, it is better to use WooCommerce’s specific methods and parameters.

    The filter woocommerce_my_account_my_orders_query uses wc_get_orders which says to use 'status' as parameter, and not 'post_status'

    The updated answer using WC_Order_Query would be

    add_filter( 'woocommerce_my_account_my_orders_query', 'unset_pending_payment_orders_from_my_account', 10, 1 );
    
    
    function unset_pending_payment_orders_from_my_account( $args ) {
        $statuses = wc_get_order_statuses();    
        unset( $statuses['wc-pending'] );
        $args['status'] = array_keys( $statuses );
        return $args;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search