• Resolved rlamb2

    (@rlamb2)


    I spent a couple days trying to figure out why an export of orders placed over the course of several months was giving a small number of duplicate entries. We’re talking like less than 20 in an export of 12,000.

    I had the same export from a few months ago and was able to diff the two reports to really lock in on what was missing and what was duplicated. At a few points throughout, I’d see an order appear twice, while an order with a close ID a couple lines removed wasn’t present at all.

    A little bit of backstory: we regularly import dozens to hundreds of orders once a month from a third-party processor (don’t ask) and all of them are set with the same date and time, usually because they get backdated a couple hours or so, sometimes a couple days. The point is, they have the exact same timestamp.

    Digging into the diffed reports I mentioned, I was really seeing the duplicate entries at points when the imported orders with the same date and time tended to align with the batch cutoff around 100.

    Took that bit of info, and tried to find where the query is set up for the order exports. Found woocommerce/src/Admin/API/Reports/Orders/Query.php which gave me the woocommerce_analytics_orders_query_args filter. From there, I backtracked around a little bit to find out I could change the orderby argument to order_id.

    Gave that a shot by hooking onto that filter for my site, and everything came out exactly as expected.

    add_filter( 'woocommerce_analytics_orders_query_args', function( $query_args ) {
            $query_args['orderby'] = 'order_id';
            return $query_args;
    } );

    That might be a place to look with an issue like these ones (they’re closed so I can’t post a reply to ask):

    My use case is such that I can use an export ordered by the ID numbers because I end up re-sorting elsewhere. I don’t know that most people would be in that boat though.

    Realistically, I probably shouldn’t have dozens or hundreds of orders with the exact same timestamp. I realize that. This particular issue wasn’t on my mind when that was written. Going back, I’ll probably offset each imported order by a second so this wouldn’t happen.

    Hopefully that can be of some help to someone else who came looking for a similar issue.

    • This topic was modified 1 year, 3 months ago by rlamb2.
Viewing 1 replies (of 1 total)
  • Howdy @rlamb2 ??

    Hopefully that can be of some help to someone else who came looking for a similar issue.

    Whoa! That can be of some help to someone else who came looking for a similar issue.

    Thank you so much for adding your input! Some of our customers might indeed find this guide helpful!

    We appreciate you being an active part of the community ??

    By the way: Good thinking on offsetting imported orders by a second, in the future.

    I’ll go ahead with marking this thread as resolved now. You’re welcome to create new ones, as needed!

    Have a wonderful day!

Viewing 1 replies (of 1 total)
  • The topic ‘Duplicate rows in Analytics Orders export’ is closed to new replies.