• Resolved ashworth

    (@ashworth)


    I have this order query using wc_get_orders that isn’t working anymore for some reason. Nobody changed the code, but this stopped working recently on a site that has a lot of order information. I have some suspicion about this being due to the amount of order data in the database, but I’ll let the community weigh in on this; because I’m really unsure.

    This is what we’ve been working with:

    $orders = wc_get_orders(array(
        'status' => array('wc-processing', 'wc-on-hold'),
        'type' => 'shop_order',
        'limit' => -1
    ));

    This produces a memory error. But if I do the following, I do get an array of ids back:

    $orders = wc_get_orders(array(
        'status' => array('wc-processing', 'wc-on-hold'),
        'type' => 'shop_order',
        'limit' => -1,
        'return' => 'ids'
    ));

    The thing is, if I remove the return argument from this, documentation says I should be getting back an object. But I don’t, I just get the error or an empty array. Limiting the number of posts isn’t helping, either.

    Is there a better or more-performant way of doing this? So far I’ve been striking out. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ashworth

    (@ashworth)

    It’s worth noting that I’ve already disabled plugins and switched to a default theme, so it’s not that. Something else is going on. Memory has also been increased as well; by as much as 2GB

    I don’t have any suggestions for your pre-existing code, but I’m going to leave this open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter ashworth

    (@ashworth)

    Thank you.

    I’m wondering if there’s a better method I should be attempting in order to fetch the order data without hitting limits like I am.

    Thread Starter ashworth

    (@ashworth)

    My test that I was conducting locally from functions.php was not wrapped in an init action or anything. Apparently it was running before CPTs were being loaded; which would be a no-go.

    Adjusting to simply limit (even with a high-ish number) is ultimately what solved this.

    $orders = wc_get_orders(array(
        'status' => array('wc-processing', 'wc-on-hold'),
        'type' => 'shop_order',
        'limit' => 1000
    ));

    For our purposes, this works. Closing this thread now. Thanks!

    • This reply was modified 3 years, 4 months ago by ashworth.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WooCommerce order query timing out with memory errors’ is closed to new replies.