Title: Cached orders?
Last modified: September 5, 2019

---

# Cached orders?

 *  [edward_plainview](https://wordpress.org/support/users/edward_plainview/)
 * (@edward_plainview)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/cached-orders/)
 * 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](https://wordpress.org/support/users/jessepearson/)
 * (@jessepearson)
 * Automattic Happiness Engineer
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12057939)
 * [@edward_plainview](https://wordpress.org/support/users/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](https://github.com/woocommerce/woocommerce/blob/3.7.1/includes/data-stores/class-wc-order-data-store-cpt.php)
 *  Thread Starter [edward_plainview](https://wordpress.org/support/users/edward_plainview/)
 * (@edward_plainview)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12058096)
 * Indeed. But should the action not represent the actual status of the order in
   the database?
 *  [jessepearson](https://wordpress.org/support/users/jessepearson/)
 * (@jessepearson)
 * Automattic Happiness Engineer
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12062320)
 * [@edward_plainview](https://wordpress.org/support/users/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](https://wordpress.org/support/users/edward_plainview/)
 * (@edward_plainview)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12062387)
 * 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](https://wordpress.org/plugins/threewp-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](https://wordpress.org/support/users/johndcoy/)
 * (@johndcoy)
 * Automattic Happiness Engineer
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12066218)
 * Hi [@edward_plainview](https://wordpress.org/support/users/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](https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties)
 * Webhooks:
    [https://woocommerce.github.io/woocommerce-rest-api-docs/#webhooks](https://woocommerce.github.io/woocommerce-rest-api-docs/#webhooks)
 *  Thread Starter [edward_plainview](https://wordpress.org/support/users/edward_plainview/)
 * (@edward_plainview)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12066238)
 * 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.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [edward_plainview](https://wordpress.org/support/users/edward_plainview/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/cached-orders/#post-12066238)
 * Status: not resolved