Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::persist_save
Helper method responsible for persisting new data to order table.
This should not contain and specific meta or actions, so that it can be used other order types safely.
Method of the class: OrdersTableDataStore{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->persist_save( $order, $force_all_fields, $backfill );
- $order(WC_Order) (required) (passed by reference — &)
- Order object.
- $force_all_fields(true|false)
- Force update all fields, instead of calculating and updating only changed fields.
Default:false - $backfill(true|false)
- Whether to backfill data to post datastore.
Default:true
OrdersTableDataStore::persist_save() OrdersTableDataStore::persist save code WC 10.7.0
protected function persist_save( &$order, bool $force_all_fields = false, $backfill = true ) {
$order->set_version( Constants::get_constant( 'WC_VERSION' ) );
$order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() );
if ( ! $order->get_date_created( 'edit' ) ) {
$order->set_date_created( time() );
}
if ( ! $order->get_date_modified( 'edit' ) ) {
$order->set_date_modified( current_time( 'mysql' ) );
}
$this->persist_order_to_db( $order, $force_all_fields );
$this->update_order_meta( $order );
$order->save_meta_data();
$order->apply_changes();
if ( $backfill ) {
self::$backfilling_order_ids[] = $order->get_id();
$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() ) );
}
$this->clear_caches( $order );
}