• Resolved devjunkie

    (@devjunkie)


    Because of a project I need help from you. I’ve searched a lot but I can’t find a solution.
    I’m trying to edit a WooCommerce function named

    – > woocommerce_account_orders

    ———-

    I’ve added the field

    – > mycustom_id

    to the the orders meta-data object because I need to get all orders which has the current logged in user in the field mycustom_id:

    – > (mycustom_id = current_user_id())

    ———-

    The check for the customer should stay. I just need to add this other current_user_id check.

    This sould stay as it is:

    – > ‘customer’ => get_current_user_id()

    ———-

    . This is my not working code snippet:

        function woocommerce_account_orders( $current_page ) {
            $current_page    = empty( $current_page ) ? 1 : absint( $current_page );
            $customer_orders = wc_get_orders( apply_filters( 'woocommerce_my_account_my_orders_query', array(
                'customer' => get_current_user_id(),
                'mycustom_id' => get_current_user_id(),
                'page'     => $current_page,
                'paginate' => true,
            ) ) );
        
            wc_get_template(
                'myaccount/orders.php',
                array(
                    'current_page'    => absint( $current_page ),
                    'customer_orders' => $customer_orders,
                    'has_orders'      => 0 < $customer_orders->total,
                )
            );
        }

    The method is located in: https://docs.woocommerce.com/wc-apidocs/source-function-woocommerce_account_orders.html#2465-2486

    ———-

    How can I add this feature to the function a smart way like a filter and how can I pass my custom parameter the right way to the function? I’ve saved the parameter as an order_meta attribute:

        [5] => WC_Meta_Data Object (
             [current_data:protected] => Array (
                  [id] => 3477
                  [key] => mycustom_id
                  [value] => 2
        )

    Thank you for your help. I’ve tried so much but I’m new in PHP and must lurn a lot.

    UPDATE: I’ve this page here but I don’t know how to do this with my parameter: https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#adding-custom-parameter-support

    • This topic was modified 6 years, 5 months ago by devjunkie.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce: How can I get orders with a custom ID in order meta data object?’ is closed to new replies.