• Resolved Dragos Cristache

    (@dragoscristache)


    Hello! I am using WooCommerce 7.7.0. For a while now (I’m sorry, I can’t remember when this all started) sometimes some orders get overwritten. For example: order 79234 (placed at 08:27 AM) has no products in the line items, but it has the correct items in the shipping line. The next order, 79235 (placed at 08:28 AM) has the products that should appear in order 79234 and the correct products of 79235. Also 79235 shows the correct products for its order in the shipping line. It looks to me that orders get overwritten somehow.

    What should I look for when debugging this issue?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Saif

    (@babylon1999)

    Hello @dragoscristache,

    Thank you for reaching out!

    The version you’re using is outdated at this point, please try updating to version 7.9.0 per the steps in this guide.

    Could you also attach a copy of your site’s System Status report? You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support” (after you scroll down a bit)”. Once done, please paste it here in your reply or via a text-sharing service like https://gist.github.com/.

    Look forward to hearing back from you.

    Thread Starter Dragos Cristache

    (@dragoscristache)

    Hello @babylon1999,

    I managed to find out the culprit for my issue. I was using the function below to store some additional info that we need for accounting reasons. After a bit of digging around I found that the item->save() part was causing a lot of issues under high traffic.

    add_action('woocommerce_checkout_create_order', 'save_regular_price_in_order', 10, 2 );
    function save_regular_price_in_order( $order, $data ) {
        foreach( $order->get_items() as $item_id => $item ){
            $product = $item->get_product();
            $regular_price = $product->get_regular_price();
            $sale_price = $product->get_sale_price();
            $item->update_meta_data( '_regular_price', $regular_price );
            $item->update_meta_data( '_sale_price', $sale_price );
            $item->save();
        }
    }

    I managed to fix it by saving once at order level instead of every line item – like this.

    add_action('woocommerce_checkout_create_order', 'save_regular_price_in_order', 10, 2 );
    function save_regular_price_in_order( $order, $data ) {
        foreach( $order->get_items() as $item_id => $item ){
            $product = $item->get_product();
            $regular_price = $product->get_regular_price();
            $sale_price = $product->get_sale_price();
            $item->update_meta_data( '_regular_price', $regular_price );
            $item->update_meta_data( '_sale_price', $sale_price );
            // $item->save();
        }
    
        $order->save();
    }

    I hope this helps anyone that encounters this issue in the future. I found some extra information on Github, in issues 17660 and 25623.

    Saif

    (@babylon1999)

    I managed to fix it by saving once at order level instead of every line item – like this.

    Nice work! :?)

    I’ll be marking the thread as solved, feel free to create a new one if you have any other questions.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Orders get overwritten’ is closed to new replies.