• WC v3.7.0

    How are you caching the orders? Why do the orders not match the actual WP_Post after a status change?

    File class-wc-order.php in the set_status() function:

    do_action( ‘woocommerce_order_edit_status’, $this->get_id(), $result[‘to’] );

    Above that line, do this:

    $post = get_post( $this->get_id() );
    echo sprintf( ‘Changing order %s status to %s: %s’, $this->get_id(), $new_status, $post->post_status );

    You will notice that $new_status is NOT the same as $post->post_status.

    Why not, and how do I commit the order changes to disk?

Viewing 6 replies - 1 through 6 (of 6 total)
  • jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @edward_plainview All work done on an order, along with other objects like Products, should be done via the CRUD methods. To save the order, you would use the save method. The CRUD method for orders can be found here:
    https://github.com/woocommerce/woocommerce/blob/3.7.1/includes/data-stores/class-wc-order-data-store-cpt.php

    Thread Starter edward_plainview

    (@edward_plainview)

    Indeed. But should the action not represent the actual status of the order in the database?

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @edward_plainview Sorry, I think I misunderstood. There are two objects here, $this and $post.

    $this is the current order object being worked on that has not yet been saved to the database with the status change.

    $post is the post object itself from the database, before the $this (order) object has been saved to reflect the change.

    Can you confirm what it is you are looking to accomplish?

    Thread Starter edward_plainview

    (@edward_plainview)

    What I am doing is hooking into the action in order to broadcast (send / duplicate) the order to other blogs in the network.

    My plugin, Broadcast, does this. I even have a nice add-on that handles WC variations, galleries, orders and other product complexities.

    It broadcasts the order in the database to the other blogs.

    Needless to say, if the action does not reflect the order in the database, then I need to hook into an action that means “this order has changed status” and not “the order in memory has changed status and will be committed to the database sometime later”.

    Is there such an action available?

    Plugin Support John Coy a11n

    (@johndcoy)

    Automattic Happiness Engineer

    Hi @edward_plainview

    Needless to say, if the action does not reflect the order in the database, then I need to hook into an action that means

    Webhooks may be a feasible option. This will allow you to identify when an action like “Order updated” is triggered. Here is also the link to our API documentation to help identify the events and properties to listen for:

    Order Properties:
    https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

    Webhooks:
    https://woocommerce.github.io/woocommerce-rest-api-docs/#webhooks

    Thread Starter edward_plainview

    (@edward_plainview)

    Using a webhook for something that is supposed to be caught internally, within the same WP network install, makes no sense.

    What would make a ton more sense would be if the action represented the actual state of the order in the database.

    Is there a function that commits the complete order object to database? That’s the only thing I’m missing: the edited order in the database.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cached orders?’ is closed to new replies.