• Resolved bowis

    (@bowis)


    I am trying to get all orders between a certain date period with wc_get_orders(), this works:

    $args = array(
    ‘status’ => ‘wc-completed’,
    ‘date_created’ => $dateRange,
    );
    $orders = wc_get_orders($args);

    I then loop through the orders which are completed (which would mean that they do have a payment method attached, or so I think), and get various data:

    foreach ($orders as $order) {
    $total = $order->get_total();
    $payment_method = $order->get_payment_method();
    }

    However, this gives me an **Uncaught Error: Call to undefined method WC_Order_Refund::get_payment_method()**

    I assume this happens because the order does not have a payment method attached? Can anybody give me anysight? Or parameters that I can add in the query so I only retrieve orders that are paid.

Viewing 2 replies - 1 through 2 (of 2 total)
  • $orders come in one of two ‘type’s, shop_order and shop_order_refund.

    In $args, you can include
    'type' => 'shop_order',
    so you won’t get any ‘shop_order_refund’ orders when you use wc_get_orders($args).

    Hi @bowis,

    Since we haven’t heard from you in a while, we’re hoping that means you were able to get this resolved. I’m going to close this thread out now.

    If you’re still having trouble, please open up a new topic and we’ll be happy to help out.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Uncaught Error: Call to undefined method WC_Order_Refund::get_payment_method()’ is closed to new replies.