Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::persist_updates
Helper method that is responsible for persisting order updates to the database.
This is expected to be reused by other order types, and should not contain any specific metadata updates or actions.
Method of the class: OrdersTableDataStore{}
No Hooks.
Returns
Array. $changes Array of changes.
Usage
// protected - for code of main (parent) or child class $result = $this->persist_updates( $order, $backfill );
- $order(WC_Order) (required) (passed by reference — &)
- Order object.
- $backfill(true|false)
- Whether to backfill data to post tables.
Default: true
OrdersTableDataStore::persist_updates() OrdersTableDataStore::persist updates code WC 10.3.5
protected function persist_updates( &$order, $backfill = true ) {
// Fetch changes.
$changes = $order->get_changes();
if ( ! isset( $changes['date_modified'] ) ) {
$order->set_date_modified( current_time( 'mysql' ) );
}
$this->persist_order_to_db( $order );
$this->update_order_meta( $order );
$order->save_meta_data();
if ( $backfill ) {
self::$backfilling_order_ids[] = $order->get_id();
$this->clear_caches( $order );
$r_order = wc_get_order( $order->get_id() ); // Refresh order to account for DB changes from post hooks.
$this->maybe_backfill_post_record( $r_order );
self::$backfilling_order_ids = array_diff( self::$backfilling_order_ids, array( $order->get_id() ) );
}
return $changes;
}